[llvm] Object: account for short output names (PR #66532)

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 10:19:25 PDT 2023


https://github.com/compnerd created https://github.com/llvm/llvm-project/pull/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.

>From 5d9072c30d994c44a76f66f5a906af222654a74c Mon Sep 17 00:00:00 2001
From: Saleem Abdulrasool <abdulras at thebrowser.company>
Date: Fri, 15 Sep 2023 10:03:10 -0700
Subject: [PATCH] Object: account for short output names

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.
---
 lld/test/COFF/implib-name.test     | 1 +
 llvm/lib/Object/COFFImportFile.cpp | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/lld/test/COFF/implib-name.test b/lld/test/COFF/implib-name.test
index 4a875ab24b74387..3ec8d823a91da15 100644
--- a/lld/test/COFF/implib-name.test
+++ b/lld/test/COFF/implib-name.test
@@ -70,3 +70,4 @@ CHECK-NODEF-DLL: default.dll
 CHECK-NODEF-DLL: default.dll
 CHECK-NODEF-DLL: default.dll
 
+# RUN: lld-link /nologo /machine:x64 /out:%T/exe %T/object.obj /entry:f /subsystem:CONSOLE
diff --git a/llvm/lib/Object/COFFImportFile.cpp b/llvm/lib/Object/COFFImportFile.cpp
index 5e3508ba34aec5a..0e99fc9373e0db7 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -140,7 +140,7 @@ class ObjectFactory {
 
 public:
   ObjectFactory(StringRef S, MachineTypes M)
-      : Machine(M), ImportName(S), Library(S.drop_back(4)),
+      : Machine(M), ImportName(S), Library(llvm::sys::path::stem(S)),
         ImportDescriptorSymbolName(("__IMPORT_DESCRIPTOR_" + Library).str()),
         NullThunkSymbolName(("\x7f" + Library + "_NULL_THUNK_DATA").str()) {}
 



More information about the llvm-commits mailing list