[lld] 339f5f7 - [ELF] Set `file` for synthesized _binary_ symbols

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 6 12:05:19 PST 2023


Author: Fangrui Song
Date: 2023-11-06T12:05:13-08:00
New Revision: 339f5f727a26e9fbe3187564e504731369609501

URL: https://github.com/llvm/llvm-project/commit/339f5f727a26e9fbe3187564e504731369609501
DIFF: https://github.com/llvm/llvm-project/commit/339f5f727a26e9fbe3187564e504731369609501.diff

LOG: [ELF] Set `file` for synthesized _binary_ symbols

Ensure the property that non-null `section` implies non-null `file`.

Added: 
    

Modified: 
    lld/ELF/InputFiles.cpp
    lld/test/ELF/duplicated-synthetic-sym.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index a0d4be8ff9885b0..8c7f2c8773f2cbc 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1769,15 +1769,15 @@ void BinaryFile::parse() {
 
   llvm::StringSaver &saver = lld::saver();
 
-  symtab.addAndCheckDuplicate(Defined{nullptr, saver.save(s + "_start"),
+  symtab.addAndCheckDuplicate(Defined{this, saver.save(s + "_start"),
                                       STB_GLOBAL, STV_DEFAULT, STT_OBJECT, 0, 0,
                                       section});
-  symtab.addAndCheckDuplicate(Defined{nullptr, saver.save(s + "_end"),
-                                      STB_GLOBAL, STV_DEFAULT, STT_OBJECT,
-                                      data.size(), 0, section});
-  symtab.addAndCheckDuplicate(Defined{nullptr, saver.save(s + "_size"),
-                                      STB_GLOBAL, STV_DEFAULT, STT_OBJECT,
-                                      data.size(), 0, nullptr});
+  symtab.addAndCheckDuplicate(Defined{this, saver.save(s + "_end"), STB_GLOBAL,
+                                      STV_DEFAULT, STT_OBJECT, data.size(), 0,
+                                      section});
+  symtab.addAndCheckDuplicate(Defined{this, saver.save(s + "_size"), STB_GLOBAL,
+                                      STV_DEFAULT, STT_OBJECT, data.size(), 0,
+                                      nullptr});
 }
 
 ELFFileBase *elf::createObjFile(MemoryBufferRef mb, StringRef archiveName,

diff  --git a/lld/test/ELF/duplicated-synthetic-sym.s b/lld/test/ELF/duplicated-synthetic-sym.s
index 0bf7800eb0ae34d..d08af3a1a52e555 100644
--- a/lld/test/ELF/duplicated-synthetic-sym.s
+++ b/lld/test/ELF/duplicated-synthetic-sym.s
@@ -10,7 +10,7 @@
 
 // CHECK:      duplicate symbol: _binary_file_bin_start
 // CHECK-NEXT: defined in {{.*}}.o
-// CHECK-NEXT: defined in <internal>
+// CHECK-NEXT: defined in file.bin
 
 .globl  _binary_file_bin_start
 _binary_file_bin_start:


        


More information about the llvm-commits mailing list