[lld] r266208 - ELF: Use hidden visibility for all DefinedSynthetic symbols.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 13 09:57:29 PDT 2016


Author: pcc
Date: Wed Apr 13 11:57:28 2016
New Revision: 266208

URL: http://llvm.org/viewvc/llvm-project?rev=266208&view=rev
Log:
ELF: Use hidden visibility for all DefinedSynthetic symbols.

This simplifies the code by allowing us to remove the visibility argument
to functions that create synthetic symbols.

The only functional change is that the visibility of the MIPS "_gp" symbol
is now hidden. Because this symbol is defined in every executable or DSO, it
would be difficult to observe a visibility change here.

Differential Revision: http://reviews.llvm.org/D19033

Modified:
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/basic-mips.s
    lld/trunk/test/ELF/mips-dynamic.s
    lld/trunk/test/ELF/mips-got-relocs.s
    lld/trunk/test/ELF/mips-gp-disp.s
    lld/trunk/test/ELF/mips-gp-local.s
    lld/trunk/test/ELF/mips-gprel32-relocs-gp0.test
    lld/trunk/test/ELF/mips-gprel32-relocs.s
    lld/trunk/test/ELF/mips-hilo-gp-disp.s

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Apr 13 11:57:28 2016
@@ -161,8 +161,8 @@ DefinedRegular<ELFT> *SymbolTable<ELFT>:
 template <class ELFT>
 SymbolBody *SymbolTable<ELFT>::addSynthetic(StringRef Name,
                                             OutputSectionBase<ELFT> &Sec,
-                                            uintX_t Val, uint8_t Visibility) {
-  auto *Sym = new (Alloc) DefinedSynthetic<ELFT>(Name, Val, Sec, Visibility);
+                                            uintX_t Val) {
+  auto *Sym = new (Alloc) DefinedSynthetic<ELFT>(Name, Val, Sec);
   resolve(Sym);
   return Sym;
 }

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Wed Apr 13 11:57:28 2016
@@ -55,7 +55,7 @@ public:
   DefinedRegular<ELFT> *addAbsolute(StringRef Name,
                                     uint8_t Visibility = llvm::ELF::STV_HIDDEN);
   SymbolBody *addSynthetic(StringRef Name, OutputSectionBase<ELFT> &Section,
-                           uintX_t Value, uint8_t Visibility);
+                           uintX_t Value);
   DefinedRegular<ELFT> *addIgnored(StringRef Name,
                                    uint8_t Visibility = llvm::ELF::STV_HIDDEN);
 

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Apr 13 11:57:28 2016
@@ -296,9 +296,8 @@ UndefinedElf<ELFT>::UndefinedElf(const E
 
 template <typename ELFT>
 DefinedSynthetic<ELFT>::DefinedSynthetic(StringRef N, uintX_t Value,
-                                         OutputSectionBase<ELFT> &Section,
-                                         uint8_t StOther)
-    : Defined(SymbolBody::DefinedSyntheticKind, N, STB_GLOBAL, StOther,
+                                         OutputSectionBase<ELFT> &Section)
+    : Defined(SymbolBody::DefinedSyntheticKind, N, STB_GLOBAL, STV_HIDDEN,
               0 /* Type */),
       Value(Value), Section(Section) {}
 

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Apr 13 11:57:28 2016
@@ -269,8 +269,8 @@ InputSectionBase<ELFT> *DefinedRegular<E
 template <class ELFT> class DefinedSynthetic : public Defined {
 public:
   typedef typename ELFT::uint uintX_t;
-  DefinedSynthetic(StringRef N, uintX_t Value, OutputSectionBase<ELFT> &Section,
-                   uint8_t StOther);
+  DefinedSynthetic(StringRef N, uintX_t Value,
+                   OutputSectionBase<ELFT> &Section);
 
   static bool classof(const SymbolBody *S) {
     return S->kind() == SymbolBody::DefinedSyntheticKind;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Apr 13 11:57:28 2016
@@ -932,11 +932,10 @@ bool Writer<ELFT>::isDiscarded(InputSect
 template <class ELFT>
 static SymbolBody *
 addOptionalSynthetic(SymbolTable<ELFT> &Table, StringRef Name,
-                     OutputSectionBase<ELFT> &Sec, typename ELFT::uint Val,
-                     uint8_t Visibility) {
+                     OutputSectionBase<ELFT> &Sec, typename ELFT::uint Val) {
   if (!Table.find(Name))
     return nullptr;
-  return Table.addSynthetic(Name, Sec, Val, Visibility);
+  return Table.addSynthetic(Name, Sec, Val);
 }
 
 // The beginning and the ending of .rel[a].plt section are marked
@@ -951,12 +950,11 @@ void Writer<ELFT>::addRelIpltSymbols() {
     return;
   StringRef S = Config->Rela ? "__rela_iplt_start" : "__rel_iplt_start";
   ElfSym<ELFT>::RelaIpltStart =
-      addOptionalSynthetic(Symtab, S, *Out<ELFT>::RelaPlt, 0, STV_HIDDEN);
+      addOptionalSynthetic(Symtab, S, *Out<ELFT>::RelaPlt, 0);
 
   S = Config->Rela ? "__rela_iplt_end" : "__rel_iplt_end";
-  ElfSym<ELFT>::RelaIpltEnd =
-      addOptionalSynthetic(Symtab, S, *Out<ELFT>::RelaPlt,
-                           DefinedSynthetic<ELFT>::SectionEnd, STV_HIDDEN);
+  ElfSym<ELFT>::RelaIpltEnd = addOptionalSynthetic(
+      Symtab, S, *Out<ELFT>::RelaPlt, DefinedSynthetic<ELFT>::SectionEnd);
 }
 
 template <class ELFT> static bool includeInSymtab(const SymbolBody &B) {
@@ -1076,18 +1074,18 @@ template <class ELFT> void Writer<ELFT>:
     // See "Global Data Symbols" in Chapter 6 in the following document:
     // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
     ElfSym<ELFT>::MipsGp =
-        Symtab.addSynthetic("_gp", *Out<ELFT>::Got, MipsGPOffset, STV_DEFAULT);
+        Symtab.addSynthetic("_gp", *Out<ELFT>::Got, MipsGPOffset);
 
     // On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
     // start of function and 'gp' pointer into GOT.
-    ElfSym<ELFT>::MipsGpDisp = addOptionalSynthetic(
-        Symtab, "_gp_disp", *Out<ELFT>::Got, MipsGPOffset, STV_HIDDEN);
+    ElfSym<ELFT>::MipsGpDisp =
+        addOptionalSynthetic(Symtab, "_gp_disp", *Out<ELFT>::Got, MipsGPOffset);
     // The __gnu_local_gp is a magic symbol equal to the current value of 'gp'
     // pointer. This symbol is used in the code generated by .cpload pseudo-op
     // in case of using -mno-shared option.
     // https://sourceware.org/ml/binutils/2004-12/msg00094.html
     ElfSym<ELFT>::MipsLocalGp = addOptionalSynthetic(
-        Symtab, "__gnu_local_gp", *Out<ELFT>::Got, MipsGPOffset, STV_HIDDEN);
+        Symtab, "__gnu_local_gp", *Out<ELFT>::Got, MipsGPOffset);
   }
 
   // In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol
@@ -1213,7 +1211,7 @@ template <class ELFT> void Writer<ELFT>:
   // Even the author of gold doesn't remember why gold behaves that way.
   // https://sourceware.org/ml/binutils/2002-03/msg00360.html
   if (isOutputDynamic())
-    Symtab.addSynthetic("_DYNAMIC", *Out<ELFT>::Dynamic, 0, STV_HIDDEN);
+    Symtab.addSynthetic("_DYNAMIC", *Out<ELFT>::Dynamic, 0);
 
   // Define __rel[a]_iplt_{start,end} symbols if needed.
   addRelIpltSymbols();
@@ -1363,9 +1361,8 @@ template <class ELFT> void Writer<ELFT>:
   auto Define = [&](StringRef Start, StringRef End,
                     OutputSectionBase<ELFT> *OS) {
     if (OS) {
-      Symtab.addSynthetic(Start, *OS, 0, STV_HIDDEN);
-      Symtab.addSynthetic(End, *OS, DefinedSynthetic<ELFT>::SectionEnd,
-                          STV_HIDDEN);
+      Symtab.addSynthetic(Start, *OS, 0);
+      Symtab.addSynthetic(End, *OS, DefinedSynthetic<ELFT>::SectionEnd);
     } else {
       Symtab.addIgnored(Start);
       Symtab.addIgnored(End);
@@ -1395,11 +1392,10 @@ void Writer<ELFT>::addStartStopSymbols(O
   StringRef Stop = Saver.save("__stop_" + S);
   if (SymbolBody *B = Symtab.find(Start))
     if (B->isUndefined())
-      Symtab.addSynthetic(Start, *Sec, 0, STV_HIDDEN);
+      Symtab.addSynthetic(Start, *Sec, 0);
   if (SymbolBody *B = Symtab.find(Stop))
     if (B->isUndefined())
-      Symtab.addSynthetic(Stop, *Sec, DefinedSynthetic<ELFT>::SectionEnd,
-                          STV_HIDDEN);
+      Symtab.addSynthetic(Stop, *Sec, DefinedSynthetic<ELFT>::SectionEnd);
 }
 
 template <class ELFT> static bool needsPtLoad(OutputSectionBase<ELFT> *Sec) {

Modified: lld/trunk/test/ELF/basic-mips.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/basic-mips.s?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/test/ELF/basic-mips.s (original)
+++ lld/trunk/test/ELF/basic-mips.s Wed Apr 13 11:57:28 2016
@@ -204,22 +204,24 @@ __start:
 # CHECK-NEXT:     Section: Undefined (0x0)
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Symbol {
-# CHECK-NEXT:     Name: __start
-# CHECK-NEXT:     Value: 0x20000
+# CHECK-NEXT:     Name: _gp
+# CHECK-NEXT:     Value: 0x37FF0
 # CHECK-NEXT:     Size: 0
-# CHECK-NEXT:     Binding: Global (0x1)
+# CHECK-NEXT:     Binding: Local
 # CHECK-NEXT:     Type: None (0x0)
-# CHECK-NEXT:     Other: 0
-# CHECK-NEXT:     Section: .text
+# CHECK-NEXT:     Other [ (0x2)
+# CHECK-NEXT:       STV_HIDDEN (0x2)
+# CHECK-NEXT:     ]
+# CHECK-NEXT:     Section: .got
 # CHECK-NEXT:   }
 # CHECK-NEXT:   Symbol {
-# CHECK-NEXT:     Name: _gp
-# CHECK-NEXT:     Value: 0x37FF0
+# CHECK-NEXT:     Name: __start
+# CHECK-NEXT:     Value: 0x20000
 # CHECK-NEXT:     Size: 0
-# CHECK-NEXT:     Binding: Global
+# CHECK-NEXT:     Binding: Global (0x1)
 # CHECK-NEXT:     Type: None (0x0)
 # CHECK-NEXT:     Other: 0
-# CHECK-NEXT:     Section: .got
+# CHECK-NEXT:     Section: .text
 # CHECK-NEXT:   }
 # CHECK-NEXT: ]
 # CHECK-NEXT: ProgramHeaders [

Modified: lld/trunk/test/ELF/mips-dynamic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-dynamic.s?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-dynamic.s (original)
+++ lld/trunk/test/ELF/mips-dynamic.s Wed Apr 13 11:57:28 2016
@@ -47,8 +47,8 @@
 # EXE-DAG:    0x70000005 MIPS_FLAGS           NOTPOT
 # EXE-DAG:    0x70000006 MIPS_BASE_ADDRESS
 # EXE-DAG:    0x7000000A MIPS_LOCAL_GOTNO     2
-# EXE-DAG:    0x70000011 MIPS_SYMTABNO        3
-# EXE-DAG:    0x70000013 MIPS_GOTSYM          0x3
+# EXE-DAG:    0x70000011 MIPS_SYMTABNO        2
+# EXE-DAG:    0x70000013 MIPS_GOTSYM          0x2
 # EXE-DAG:    0x70000016 MIPS_RLD_MAP         [[RLDMAPADDR]]
 # EXE:      ]
 
@@ -73,7 +73,6 @@
 # DSO:          Name: @
 # DSO:          Name: __start@
 # DSO:          Name: _foo@
-# DSO:          Name: _gp@
 # DSO:      ]
 # DSO:      DynamicSection [
 # DSO-NEXT:   Tag        Type                 Name/Value
@@ -82,8 +81,8 @@
 # DSO-DAG:    0x70000005 MIPS_FLAGS           NOTPOT
 # DSO-DAG:    0x70000006 MIPS_BASE_ADDRESS    0x0
 # DSO-DAG:    0x7000000A MIPS_LOCAL_GOTNO     2
-# DSO-DAG:    0x70000011 MIPS_SYMTABNO        4
-# DSO-DAG:    0x70000013 MIPS_GOTSYM          0x4
+# DSO-DAG:    0x70000011 MIPS_SYMTABNO        3
+# DSO-DAG:    0x70000013 MIPS_GOTSYM          0x3
 # DSO:      ]
 
   .text

Modified: lld/trunk/test/ELF/mips-got-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-got-relocs.s?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-got-relocs.s (original)
+++ lld/trunk/test/ELF/mips-got-relocs.s Wed Apr 13 11:57:28 2016
@@ -47,9 +47,9 @@ v1:
 # EXE_SYM: Sections:
 # EXE_SYM: .got 0000000c 0000000000030000 DATA
 # EXE_SYM: SYMBOL TABLE:
-# EXE_SYM: 00040000 g       .data		 00000004 v1
-# EXE_SYM: 00037ff0         .got		 00000000 _gp
+# EXE_SYM: 00037ff0         .got		 00000000 .hidden _gp
 #          ^-- .got + GP offset (0x7ff0)
+# EXE_SYM: 00040000 g       .data		 00000004 v1
 
 
 # EXE_GOT_BE: Contents of section .got:
@@ -71,9 +71,9 @@ v1:
 # DSO_SYM: Sections:
 # DSO_SYM: .got 0000000c 0000000000020000 DATA
 # DSO_SYM: SYMBOL TABLE:
-# DSO_SYM: 00030000 g       .data		 00000004 v1
-# DSO_SYM: 00027ff0         .got		 00000000 _gp
+# DSO_SYM: 00027ff0         .got		 00000000 .hidden _gp
 #          ^-- .got + GP offset (0x7ff0)
+# DSO_SYM: 00030000 g       .data		 00000004 v1
 
 # DSO_GOT_BE: Contents of section .got:
 # DSO_GOT_BE:  20000 00000000 80000000 00030000

Modified: lld/trunk/test/ELF/mips-gp-disp.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-gp-disp.s?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-gp-disp.s (original)
+++ lld/trunk/test/ELF/mips-gp-disp.s Wed Apr 13 11:57:28 2016
@@ -24,7 +24,7 @@
 # DIS-NEXT:    10000:  3c 08 00 01  lui   $8, 1
 # DIS-NEXT:    10004:  21 08 7f f0  addi  $8, $8, 32752
 #                                                 ^-- 0x37ff0 & 0xffff
-# DIS: 00027ff0  .got  00000000 _gp
+# DIS: 00027ff0  .got  00000000 .hidden _gp
 
 # REL:      Relocations [
 # REL-NEXT: ]

Modified: lld/trunk/test/ELF/mips-gp-local.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-gp-local.s?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-gp-local.s (original)
+++ lld/trunk/test/ELF/mips-gp-local.s Wed Apr 13 11:57:28 2016
@@ -11,7 +11,7 @@
 # CHECK-NEXT:    20000:  3c 08 00 03  lui   $8, 3
 # CHECK-NEXT:    20004:  21 08 7f f0  addi  $8, $8, 32752
 
-# CHECK: 00037ff0  .got  00000000 _gp
+# CHECK: 00037ff0  .got  00000000 .hidden _gp
 
   .text
   .globl  __start

Modified: lld/trunk/test/ELF/mips-gprel32-relocs-gp0.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-gprel32-relocs-gp0.test?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-gprel32-relocs-gp0.test (original)
+++ lld/trunk/test/ELF/mips-gprel32-relocs-gp0.test Wed Apr 13 11:57:28 2016
@@ -28,4 +28,4 @@
 # CHECK: SYMBOL TABLE:
 # CHECK: 00010000         .text          00000000 foo
 # CHECK: 00010010         .text          00000000 bar
-# CHECK: 00027ff0         .got           00000000 _gp
+# CHECK: 00027ff0         .got           00000000 .hidden _gp

Modified: lld/trunk/test/ELF/mips-gprel32-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-gprel32-relocs.s?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-gprel32-relocs.s (original)
+++ lld/trunk/test/ELF/mips-gprel32-relocs.s Wed Apr 13 11:57:28 2016
@@ -28,4 +28,4 @@ v1:
 # CHECK: SYMBOL TABLE:
 # CHECK: 00010008         .text           00000000 bar
 # CHECK: 00010004         .text           00000000 foo
-# CHECK: 00027ff0         .got           00000000 _gp
+# CHECK: 00027ff0         .got           00000000 .hidden _gp

Modified: lld/trunk/test/ELF/mips-hilo-gp-disp.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-hilo-gp-disp.s?rev=266208&r1=266207&r2=266208&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-hilo-gp-disp.s (original)
+++ lld/trunk/test/ELF/mips-hilo-gp-disp.s Wed Apr 13 11:57:28 2016
@@ -25,9 +25,9 @@ __start:
 #                                                  ^-- %lo(0x37ff0-0x20004+4)
 
 # EXE: SYMBOL TABLE:
+# EXE: 00037ff0     .got    00000000 .hidden _gp
 # EXE: 00020000     .text   00000000 __start
 # EXE: 00020010     .text   00000000 _foo
-# EXE: 00037ff0     .got    00000000 _gp
 
 # SO:      Disassembly of section .text:
 # SO-NEXT: __start:
@@ -37,6 +37,6 @@ __start:
 #                                                 ^-- %lo(0x27ff0-0x10004+4)
 
 # SO: SYMBOL TABLE:
+# SO: 00027ff0     .got    00000000 .hidden _gp
 # SO: 00010000     .text   00000000 __start
 # SO: 00010010     .text   00000000 _foo
-# SO: 00027ff0     .got    00000000 _gp




More information about the llvm-commits mailing list