[PATCH] D34673: [ELF] - Do not set st_size field of SHT_UNDEF symbols

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 02:51:50 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL306526: [ELF] - Do not set st_size field of SHT_UNDEF symbols. (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D34673?vs=104110&id=104368#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34673

Files:
  lld/trunk/ELF/SyntheticSections.cpp
  lld/trunk/test/ELF/Inputs/dso-undef-size.s
  lld/trunk/test/ELF/dso-undef-size.s


Index: lld/trunk/test/ELF/Inputs/dso-undef-size.s
===================================================================
--- lld/trunk/test/ELF/Inputs/dso-undef-size.s
+++ lld/trunk/test/ELF/Inputs/dso-undef-size.s
@@ -0,0 +1,4 @@
+.text
+.global foo
+.size foo, 4
+foo:
Index: lld/trunk/test/ELF/dso-undef-size.s
===================================================================
--- lld/trunk/test/ELF/dso-undef-size.s
+++ lld/trunk/test/ELF/dso-undef-size.s
@@ -0,0 +1,32 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/dso-undef-size.s -o %t1.o
+# RUN: ld.lld -shared %t1.o -o %t1.so
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o
+# RUN: ld.lld -shared %t2.o %t1.so -o %t2.so
+# RUN: llvm-readobj -symbols -dyn-symbols %t2.so
+
+# CHECK:      Symbols [
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: foo
+# CHECK-NEXT:     Value:
+# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Binding:
+# CHECK-NEXT:     Type:
+# CHECK-NEXT:     Other:
+# CHECK-NEXT:     Section: Undefined
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+# CHECK:      DynamicSymbols [
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name: foo
+# CHECK-NEXT:     Value:
+# CHECK-NEXT:     Size: 0
+# CHECK-NEXT:     Binding:
+# CHECK-NEXT:     Type:
+# CHECK-NEXT:     Other:
+# CHECK-NEXT:     Section: Undefined
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
+.text
+.global foo
Index: lld/trunk/ELF/SyntheticSections.cpp
===================================================================
--- lld/trunk/ELF/SyntheticSections.cpp
+++ lld/trunk/ELF/SyntheticSections.cpp
@@ -1376,7 +1376,6 @@
     }
 
     ESym->st_name = Ent.StrTabOffset;
-    ESym->st_size = Body->getSize<ELFT>();
 
     // Set a section index.
     if (const OutputSection *OutSec = Body->getOutputSection())
@@ -1386,6 +1385,14 @@
     else if (isa<DefinedCommon>(Body))
       ESym->st_shndx = SHN_COMMON;
 
+    // Copy symbol size if it is a defined symbol. st_size is not significant
+    // for undefined symbols, so whether copying it or not is up to us if that's
+    // the case. We'll leave it as zero because by not setting a value, we can
+    // get the exact same outputs for two sets of input files that differ only
+    // in undefined symbol size in DSOs.
+    if (ESym->st_shndx != SHN_UNDEF)
+      ESym->st_size = Body->getSize<ELFT>();
+
     // st_value is usually an address of a symbol, but that has a
     // special meaining for uninstantiated common symbols (this can
     // occur if -r is given).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34673.104368.patch
Type: text/x-patch
Size: 2515 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170628/a76f5a49/attachment.bin>


More information about the llvm-commits mailing list