Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[ELF] - Make __start_/__stop_<section_name> symbols STV_PROTECTED
Browse files Browse the repository at this point in the history
There are no reasons for them to be STV_DEFAULT,
recently bfd did the same change.

Differential revision: https://reviews.llvm.org/D44566

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@327983 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
George Rimar committed Mar 20, 2018
1 parent 07bab16 commit 34412fc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1629,8 +1629,8 @@ void Writer<ELFT>::addStartStopSymbols(OutputSection *Sec) {
StringRef S = Sec->Name;
if (!isValidCIdentifier(S))
return;
addOptionalRegular(Saver.save("__start_" + S), Sec, 0, STV_DEFAULT);
addOptionalRegular(Saver.save("__stop_" + S), Sec, -1, STV_DEFAULT);
addOptionalRegular(Saver.save("__start_" + S), Sec, 0, STV_PROTECTED);
addOptionalRegular(Saver.save("__stop_" + S), Sec, -1, STV_PROTECTED);
}

static bool needsPtLoad(OutputSection *Sec) {
Expand Down
22 changes: 17 additions & 5 deletions test/ELF/startstop-shared.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,30 @@
.quad __start_bar
.section bar,"a"

// Test that we are able to hide the symbol.
// CHECK: R_X86_64_RELATIVE - 0x[[ADDR:.*]]
// CHECK: Relocations [
// CHECK-NEXT: Section {{.*}} .rela.dyn {
// CHECK-NEXT: R_X86_64_RELATIVE
// CHECK-NEXT: R_X86_64_RELATIVE
// CHECK-NEXT: }
// CHECK-NEXT: ]

// By default the symbol is visible and we need a dynamic reloc.
// CHECK: R_X86_64_64 __start_foo 0x0
// Test that we are able to hide the symbol.
// By default the symbol is protected.

// CHECK: Name: __start_bar
// CHECK-NEXT: Value: 0x[[ADDR]]
// CHECK-NEXT: Value:
// CHECK-NEXT: Size:
// CHECK-NEXT: Binding: Local
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other [
// CHECK-NEXT: STV_HIDDEN
// CHECK-NEXT: ]

// CHECK: Name: __start_foo
// CHECK-NEXT: Value:
// CHECK-NEXT: Size:
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: None
// CHECK-NEXT: Other [
// CHECK-NEXT: STV_PROTECTED
// CHECK-NEXT: ]
15 changes: 7 additions & 8 deletions test/ELF/startstop.s
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
// DISASM: 1013: 90 nop
// DISASM: 1014: 90 nop


// SYMBOL: Relocations [
// SYMBOL-NEXT: Section ({{.*}}) .rela.dyn {
// SYMBOL-NEXT: 0x2010 R_X86_64_64 __stop_zed1 0x0
// SYMBOL-NEXT: 0x2018 R_X86_64_64 __stop_zed1 0x1
// SYMBOL-NEXT: 0x2000 R_X86_64_64 __stop_zed2 0x0
// SYMBOL-NEXT: 0x2008 R_X86_64_64 __stop_zed2 0x1
// SYMBOL-NEXT: R_X86_64_RELATIVE
// SYMBOL-NEXT: R_X86_64_RELATIVE
// SYMBOL-NEXT: R_X86_64_RELATIVE
// SYMBOL-NEXT: R_X86_64_RELATIVE
// SYMBOL-NEXT: }
// SYMBOL-NEXT: ]

Expand All @@ -45,20 +44,20 @@
// SYMBOL: Symbol {
// SYMBOL: Name: __stop_foo
// SYMBOL: Value: 0x1012
// STMBOL: STV_HIDDEN
// SYMBOL: STV_HIDDEN
// SYMBOL: Section: foo
// SYMBOL: }

// SYMBOL: Symbol {
// SYMBOL: Name: __stop_zed1
// SYMBOL: Value: 0x2010
// STMBOL: Other: 0
// SYMBOL: STV_PROTECTED
// SYMBOL: Section: zed1
// SYMBOL: }
// SYMBOL: Symbol {
// SYMBOL: Name: __stop_zed2
// SYMBOL: Value: 0x2020
// STMBOL: Other: 0
// SYMBOL: STV_PROTECTED
// SYMBOL: Section: zed2
// SYMBOL: }

Expand Down

0 comments on commit 34412fc

Please sign in to comment.