diff --git a/llvm/test/tools/llvm-nm/XCOFF/export-symbols.test b/llvm/test/tools/llvm-nm/XCOFF/export-symbols.test --- a/llvm/test/tools/llvm-nm/XCOFF/export-symbols.test +++ b/llvm/test/tools/llvm-nm/XCOFF/export-symbols.test @@ -52,6 +52,11 @@ # 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 "#!" > imp.txt +# RUN: llvm-nm --export-symbols imp.txt 2>&1 | FileCheck --allow-empty --implicit-check-not={{.}} %s + --- !XCOFF FileHeader: MagicNumber: 0x1DF diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -2262,6 +2262,13 @@ if (error(BufferOrErr.getError(), Filename)) return SymbolList; + // Ignore AIX linker import files (these files start with "#!"), when + // exporting symbols. + const char *BuffStart = (*BufferOrErr)->getBufferStart(); + if (ExportSymbols && (*BufferOrErr)->getBufferSize() >= 2 && + BuffStart[0] == '#' && BuffStart[1] == '!') + return SymbolList; + LLVMContext Context; LLVMContext *ContextPtr = NoLLVMBitcode ? nullptr : &Context; Expected> BinaryOrErr =