[lld] r279220 - [ELF] - Do not change binding of symbols when creating relocatable output.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 19 01:31:02 PDT 2016
Author: grimar
Date: Fri Aug 19 03:31:02 2016
New Revision: 279220
URL: http://llvm.org/viewvc/llvm-project?rev=279220&view=rev
Log:
[ELF] - Do not change binding of symbols when creating relocatable output.
Spec says "A hidden symbol contained in a relocatable object must be either
removed or converted to STB_LOCAL binding by the link-editor when the
relocatable object is included in an executable file or shared object".
But we previously converted symbols to STB_LOCAL even when -r was specified.
Broken binary was produced, this is PR28967, patch fixes the issue.
Differential revision: https://reviews.llvm.org/D23514
Added:
lld/trunk/test/ELF/relocatable-visibility.s
Modified:
lld/trunk/ELF/OutputSections.cpp
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=279220&r1=279219&r2=279220&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Aug 19 03:31:02 2016
@@ -1316,6 +1316,8 @@ static bool sortMipsSymbols(const std::p
static uint8_t getSymbolBinding(SymbolBody *Body) {
Symbol *S = Body->symbol();
+ if (Config->Relocatable)
+ return S->Binding;
uint8_t Visibility = S->Visibility;
if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
return STB_LOCAL;
Added: lld/trunk/test/ELF/relocatable-visibility.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-visibility.s?rev=279220&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-visibility.s (added)
+++ lld/trunk/test/ELF/relocatable-visibility.s Fri Aug 19 03:31:02 2016
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld -r %t.o -o %t1
+# RUN: llvm-readobj -t %t1 | FileCheck --check-prefix=RELOCATABLE %s
+
+# RELOCATABLE: Name: foo
+# RELOCATABLE-NEXT: Value: 0x0
+# RELOCATABLE-NEXT: Size: 0
+# RELOCATABLE-NEXT: Binding: Global
+# RELOCATABLE-NEXT: Type: None
+# RELOCATABLE-NEXT: Other [
+# RELOCATABLE-NEXT: STV_HIDDEN
+# RELOCATABLE-NEXT: ]
+# RELOCATABLE-NEXT: Section: Undefined
+
+.global _start
+_start:
+ callq foo
+ .hidden foo
More information about the llvm-commits
mailing list