summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2017-06-28 09:51:33 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2017-06-28 09:51:33 +0000
commitdbe843d602488af7b8095babf582db65fa8a4b4e (patch)
treec226d5b61c67b79bf3fdc8c198ad7b372cae823a
parentb01e6b5a521120626368d9b8999fde67c45055c8 (diff)
downloadbcm5719-llvm-dbe843d602488af7b8095babf582db65fa8a4b4e.tar.gz
bcm5719-llvm-dbe843d602488af7b8095babf582db65fa8a4b4e.zip
[ELF] - Do not set st_size field of SHT_UNDEF symbols.
This fixes PR33598. Size field for undefined symbols is not significant. Setting it to fixed value, like zero, may be useful though. For example when we have 2 DSO's, like in this PR, if lower level DSO may change slightly (in part of some symbol's st_size) and higher-level DSO is rebuilt, then tools that monitoring checksum of high level DSO file can notice it and trigger cascade of some other unnecessary actions. If we set st_size to zero, that can be avoided. Differential revision: https://reviews.llvm.org/D34673 llvm-svn: 306526
-rw-r--r--lld/ELF/SyntheticSections.cpp9
-rw-r--r--lld/test/ELF/Inputs/dso-undef-size.s4
-rw-r--r--lld/test/ELF/dso-undef-size.s32
3 files changed, 44 insertions, 1 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index cb1494d427a..4c5b4f30f2c 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1376,7 +1376,6 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
}
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 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
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).
diff --git a/lld/test/ELF/Inputs/dso-undef-size.s b/lld/test/ELF/Inputs/dso-undef-size.s
new file mode 100644
index 00000000000..424f56f82b7
--- /dev/null
+++ b/lld/test/ELF/Inputs/dso-undef-size.s
@@ -0,0 +1,4 @@
+.text
+.global foo
+.size foo, 4
+foo:
diff --git a/lld/test/ELF/dso-undef-size.s b/lld/test/ELF/dso-undef-size.s
new file mode 100644
index 00000000000..5a235565bbc
--- /dev/null
+++ b/lld/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
OpenPOWER on IntegriCloud