[llvm] adc317d - llvm-nm ignore the Import symbol file for the --export-symbol option.
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 30 12:47:14 PDT 2023
Author: zhijian
Date: 2023-08-30T15:45:37-04:00
New Revision: adc317d36908f856821df94bd8983a3ec8dae148
URL: https://github.com/llvm/llvm-project/commit/adc317d36908f856821df94bd8983a3ec8dae148
DIFF: https://github.com/llvm/llvm-project/commit/adc317d36908f856821df94bd8983a3ec8dae148.diff
LOG: llvm-nm ignore the Import symbol file for the --export-symbol option.
Summary:
On AIX OS, clang may use llvm-nm to export the symbols from all input files (see https://github.com/llvm/llvm-project/blob/515c435e378b243b1be3da1587c9e206055f2c32/clang/lib/Driver/ToolChains/AIX.cpp#L236). However, the clang command-line may include import files (identified by them starting with #!). llvm-nm previously reported "invalid object file" errors for import files, meaning that the clang driver would fail to link when import files are included this way.
In this patch, llvm-nm is changed to ignore import files when the --export-symbol option, meaning that clang will now succeed in this case.
For more information about AIX import files, see https://www.ibm.com/docs/en/aix/7.3?topic=l-ld-command
Reviewers: Hubert Tong, James Henderson, MaskRay, Stephen Peckham
Differential Revision: https://reviews.llvm.org/D158004
Added:
Modified:
llvm/test/tools/llvm-nm/XCOFF/export-symbols.test
llvm/tools/llvm-nm/llvm-nm.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-nm/XCOFF/export-symbols.test b/llvm/test/tools/llvm-nm/XCOFF/export-symbols.test
index 8cedd2e2040074..cea2336befe0ed 100644
--- a/llvm/test/tools/llvm-nm/XCOFF/export-symbols.test
+++ b/llvm/test/tools/llvm-nm/XCOFF/export-symbols.test
@@ -52,6 +52,10 @@
# RUN: yaml2obj -DFLAG=0x2000 --docnum=2 %s -o %t_shared.o
# RUN: llvm-nm --export-symbols %t_shared.o | count 0
+## Test that llvm-nm ignores AIX linker import files when using --export-symbols. These start with "#!".
+# RUN: echo -e "#!\n bar\n foo " > %t_imp.txt
+# RUN: llvm-nm --export-symbols %t_imp.txt 2>&1 | count 0
+
--- !XCOFF
FileHeader:
MagicNumber: 0x1DF
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index e10bbf8a139799..4aa585291bd782 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -2268,6 +2268,14 @@ static std::vector<NMSymbol> dumpSymbolNamesFromFile(StringRef Filename) {
if (error(BufferOrErr.getError(), Filename))
return SymbolList;
+ // Ignore AIX linker import files (these files start with "#!"), when
+ // exporting symbols.
+ const char *BuffStart = (*BufferOrErr)->getBufferStart();
+ size_t BufferSize = (*BufferOrErr)->getBufferSize();
+ if (ExportSymbols && BufferSize >= 2 && BuffStart[0] == '#' &&
+ BuffStart[1] == '!')
+ return SymbolList;
+
LLVMContext Context;
LLVMContext *ContextPtr = NoLLVMBitcode ? nullptr : &Context;
Expected<std::unique_ptr<Binary>> BinaryOrErr =
More information about the llvm-commits
mailing list