[PATCH] D158004: llvm-nm ignore the Import symbol file for the --export-symbol option.
Digger Lin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 15 10:52:39 PDT 2023
DiggerLin created this revision.
DiggerLin added reviewers: stephenpeckham, hubert.reinterpretcast, jhenderson.
Herald added a project: All.
DiggerLin requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.
in the https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/AIX.cpp#L236,
clang use llvm-nm to export symbol, but the input of the clang command line maybe include the imported symbol files(the first line of file begin with #!) which do not need to be exported by `llvm-nm --export-symbols'.
`llvm-nm --export-symbols` reports "a invalid object file" error on the the Imported symbol files currently. When Clang driver invoke the `llvm-nm --export-symbols` on imported symbol file, it will cause the clang has linker error on AIX OS.
in the patch, the llvm-nm ignore the Import symbol file for the --export-symbol option. it will fix above defect.
in t
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158004
Files:
llvm/test/tools/llvm-nm/XCOFF/export-symbols.test
llvm/tools/llvm-nm/llvm-nm.cpp
Index: llvm/tools/llvm-nm/llvm-nm.cpp
===================================================================
--- llvm/tools/llvm-nm/llvm-nm.cpp
+++ llvm/tools/llvm-nm/llvm-nm.cpp
@@ -2262,6 +2262,14 @@
if (error(BufferOrErr.getError(), Filename))
return SymbolList;
+ // Ignore parsing an imported symbol file that begins with #! when we export
+ // 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 =
Index: llvm/test/tools/llvm-nm/XCOFF/export-symbols.test
===================================================================
--- llvm/test/tools/llvm-nm/XCOFF/export-symbols.test
+++ 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 ignoring the parsing an imported symbol file that begins with #!
+# RUN: echo "#!" > imp.txt
+# RUN: llvm-nm --export-symbols imp.txt 2>&1 | FileCheck --allow-empty --implicit-check-not={{.}} %s
+
--- !XCOFF
FileHeader:
MagicNumber: 0x1DF
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158004.550390.patch
Type: text/x-patch
Size: 1374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230815/c1b6dee6/attachment.bin>
More information about the llvm-commits
mailing list