summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-04-12 20:41:42 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-04-12 20:41:42 +0000
commit173ee84530ece36de821a00db1ecee1070323f52 (patch)
tree6e8316c9b685ee553324aa164605b435470b7f71
parent2e379fc76733b7dfded8c0487c44073c8e484fa2 (diff)
downloadbcm5719-llvm-173ee84530ece36de821a00db1ecee1070323f52.tar.gz
bcm5719-llvm-173ee84530ece36de821a00db1ecee1070323f52.zip
ELF: Give automatically generated __start_* and __stop_* symbols hidden visibility.
These symbols describe a property of a linkage unit, so it seems reasonable to limit their visibility to the linkage unit. Furthermore the use cases I am aware of do not require more than hidden visibility. This is a departure from the behavior of the bfd and gold linkers. However, it is unclear that the decision to give these symbols default visibility in those linkers was made deliberately. The __start_*/__stop_* feature was added to the bfd linker in 1994 [1], while the visibility feature was added about five years later [2], so it may have been that the visibility of these symbols was not considered. The feature was implemented in gold [3] in the same way; the behavior may have simply been copied from bfd. The only related discussion I could find on the binutils mailing list [4] was a user issue which would most likely not have occurred if the symbols had hidden visibility. [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=5efddb2e7c3229b569a862205f61d42860af678b [2] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=0fc731e447cd01e7fc35197b487ff0e4fd25afca [3] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bfd58944a64b0997a310b95fbe0423338961e71c [4] https://sourceware.org/ml/binutils/2014-05/msg00011.html Differential Revision: http://reviews.llvm.org/D19024 llvm-svn: 266121
-rw-r--r--lld/ELF/Writer.cpp4
-rw-r--r--lld/test/ELF/startstop-shared.s14
2 files changed, 9 insertions, 9 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 4bbd812dec7..a28d910f2ad 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1261,11 +1261,11 @@ void Writer<ELFT>::addStartStopSymbols(OutputSectionBase<ELFT> *Sec) {
StringRef Stop = Saver.save("__stop_" + S);
if (SymbolBody *B = Symtab.find(Start))
if (B->isUndefined())
- Symtab.addSynthetic(Start, *Sec, 0, STV_DEFAULT);
+ Symtab.addSynthetic(Start, *Sec, 0, STV_HIDDEN);
if (SymbolBody *B = Symtab.find(Stop))
if (B->isUndefined())
Symtab.addSynthetic(Stop, *Sec, DefinedSynthetic<ELFT>::SectionEnd,
- STV_DEFAULT);
+ STV_HIDDEN);
}
template <class ELFT> static bool needsPtLoad(OutputSectionBase<ELFT> *Sec) {
diff --git a/lld/test/ELF/startstop-shared.s b/lld/test/ELF/startstop-shared.s
index 9c18d36b02b..0e52bac2621 100644
--- a/lld/test/ELF/startstop-shared.s
+++ b/lld/test/ELF/startstop-shared.s
@@ -5,21 +5,21 @@
.quad __start_foo
.section foo,"a"
-// By default the symbol is visible and we need a dynamic reloc.
-// CHECK: R_X86_64_64 __start_foo 0x0
+// By default the symbol is hidden.
+// CHECK: R_X86_64_RELATIVE - 0x[[ADDR1:.*]]
.hidden __start_bar
.quad __start_bar
.section bar,"a"
-// Test that we are able to hide the symbol.
-// CHECK: R_X86_64_RELATIVE - 0x[[ADDR:.*]]
+// References do not affect the visibility.
+// CHECK: R_X86_64_RELATIVE - 0x[[ADDR2:.*]]
// CHECK: Name: __start_bar
-// CHECK-NEXT: Value: 0x[[ADDR]]
+// CHECK-NEXT: Value: 0x[[ADDR2]]
// CHECK-NEXT: Size:
// CHECK-NEXT: Binding: Local
// CHECK: Name: __start_foo
-// CHECK-NEXT: Value:
+// CHECK-NEXT: Value: 0x[[ADDR1]]
// CHECK-NEXT: Size:
-// CHECK-NEXT: Binding: Global
+// CHECK-NEXT: Binding: Local
OpenPOWER on IntegriCloud