[lld] r266424 - Two small related fixes.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 15 04:57:09 PDT 2016
Author: rafael
Date: Fri Apr 15 06:57:07 2016
New Revision: 266424
URL: http://llvm.org/viewvc/llvm-project?rev=266424&view=rev
Log:
Two small related fixes.
* A hidden undefined is not preemptable.
* It is always zero, so we don't need a dynamic reloc for it.
Added:
lld/trunk/test/ELF/weak-undef-hidden.s
Modified:
lld/trunk/ELF/Symbols.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=266424&r1=266423&r2=266424&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Fri Apr 15 06:57:07 2016
@@ -121,6 +121,9 @@ bool SymbolBody::isPreemptible() const {
if (isShared())
return true;
+ if (getVisibility() != STV_DEFAULT)
+ return false;
+
if (isUndefined()) {
if (!isWeak())
return true;
@@ -137,8 +140,6 @@ bool SymbolBody::isPreemptible() const {
if (!Config->Shared)
return false;
- if (getVisibility() != STV_DEFAULT)
- return false;
if (Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc()))
return false;
return true;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=266424&r1=266423&r2=266424&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Apr 15 06:57:07 2016
@@ -618,7 +618,7 @@ void Writer<ELFT>::scanRelocs(InputSecti
// can process some of it and and just ask the dynamic linker to add the
// load address.
if (!Config->Pic || Target->isRelRelative(Type) || Expr == R_PC ||
- Expr == R_SIZE) {
+ Expr == R_SIZE || (Body.isUndefined() && Body.isWeak())) {
if (Config->EMachine == EM_MIPS && Body.isLocal() &&
(Type == R_MIPS_GPREL16 || Type == R_MIPS_GPREL32))
Expr = R_MIPS_GP0;
Added: lld/trunk/test/ELF/weak-undef-hidden.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/weak-undef-hidden.s?rev=266424&view=auto
==============================================================================
--- lld/trunk/test/ELF/weak-undef-hidden.s (added)
+++ lld/trunk/test/ELF/weak-undef-hidden.s Fri Apr 15 06:57:07 2016
@@ -0,0 +1,29 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: ld.lld %t.o -o %t.so -shared
+// RUN: llvm-readobj -r -s -section-data %t.so | FileCheck %s
+
+.data
+.weak g
+.hidden g
+.quad g
+
+// CHECK: Name: .data
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: SHF_ALLOC
+// CHECK-NEXT: SHF_WRITE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address:
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size: 8
+// CHECK-NEXT: Link: 0
+// CHECK-NEXT: Info: 0
+// CHECK-NEXT: AddressAlignment: 1
+// CHECK-NEXT: EntrySize: 0
+// CHECK-NEXT: SectionData (
+// CHECK-NEXT: 0000: 00000000 00000000
+// CHECK-NEXT: )
+
+// CHECK: Relocations [
+// CHECK-NEXT: ]
More information about the llvm-commits
mailing list