Skip to content

Commit 401296f

Browse files
authored
Object: account for short output names (#66532)
The import library thunk name suffix uses the stem of the file. We currently would attempt to trim the suffix by dropping the trailing 4 characters (under the assumption that the output name was `.lib`). This now uses the `llvm::sys::path` API for computing the stem. This avoids an assertion failure when the name is less the 4 characters and assertions are enabled.
1 parent cbdccb3 commit 401296f

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lld/test/COFF/implib-name.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ CHECK-NODEF-DLL: default.dll
7070
CHECK-NODEF-DLL: default.dll
7171
CHECK-NODEF-DLL: default.dll
7272

73+
# RUN: lld-link /nologo /machine:x64 /out:%T/exe %T/object.obj /entry:f /subsystem:CONSOLE

llvm/lib/Object/COFFImportFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class ObjectFactory {
140140

141141
public:
142142
ObjectFactory(StringRef S, MachineTypes M)
143-
: Machine(M), ImportName(S), Library(S.drop_back(4)),
143+
: Machine(M), ImportName(S), Library(llvm::sys::path::stem(S)),
144144
ImportDescriptorSymbolName(("__IMPORT_DESCRIPTOR_" + Library).str()),
145145
NullThunkSymbolName(("\x7f" + Library + "_NULL_THUNK_DATA").str()) {}
146146

0 commit comments

Comments
 (0)