From d3e13b58cd083bb2c23d8addc4ae3c6238777867 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 7 Feb 2021 18:21:36 -0800 Subject: [PATCH] ELFObjectWriter: Don't de-duplicate STT_FILE symbols --- llvm/include/llvm/MC/MCAssembler.h | 3 --- llvm/lib/MC/ELFObjectWriter.cpp | 1 - llvm/test/MC/ELF/file.s | 8 ++++++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h index cbda472d0bb5..63b8c4b63bcf 100644 --- a/llvm/include/llvm/MC/MCAssembler.h +++ b/llvm/include/llvm/MC/MCAssembler.h @@ -450,9 +450,6 @@ public: } void addFileName(StringRef FileName) { - for (const std::pair &F : FileNames) - if (F.first == FileName) - return; FileNames.emplace_back(std::string(FileName), Symbols.size()); } diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index a21194f52da5..9257e3bff631 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -725,7 +725,6 @@ void ELFWriter::computeSymbolTable( StrTabBuilder.finalize(); // Symbols are required to be in lexicographic order. - //array_pod_sort(LocalSymbolData.begin(), LocalSymbolData.end()); array_pod_sort(ExternalSymbolData.begin(), ExternalSymbolData.end()); // Make the first STT_FILE precede previous local symbols. diff --git a/llvm/test/MC/ELF/file.s b/llvm/test/MC/ELF/file.s index 9ede62948cfb..e750762c9970 100644 --- a/llvm/test/MC/ELF/file.s +++ b/llvm/test/MC/ELF/file.s @@ -10,8 +10,9 @@ # CHECK-NEXT: 7: 0000000000000000 0 NOTYPE LOCAL DEFAULT 6 local1 # CHECK-NEXT: 8: 0000000000000000 0 SECTION LOCAL DEFAULT 8 bar1 # CHECK-NEXT: 9: 0000000000000000 0 NOTYPE LOCAL DEFAULT 8 local2 -# CHECK-NEXT: 10: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 6 bar.c -# CHECK-NEXT: 11: 0000000000000008 0 NOTYPE GLOBAL DEFAULT 2 foo.c +# CHECK-NEXT: 10: 0000000000000000 0 FILE LOCAL DEFAULT ABS bar.c +# CHECK-NEXT: 11: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 6 bar.c +# CHECK-NEXT: 12: 0000000000000008 0 NOTYPE GLOBAL DEFAULT 2 foo.c .quad .text @@ -34,3 +35,6 @@ local1: .section bar1,"a" local2: .quad bar1 + +## STT_FILE symbols of the same name are not de-duplicated. +.file "bar.c"