[lld] r297366 - [ELF] - Implemented -znotext
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 9 00:48:35 PST 2017
Author: grimar
Date: Thu Mar 9 02:48:34 2017
New Revision: 297366
URL: http://llvm.org/viewvc/llvm-project?rev=297366&view=rev
Log:
[ELF] - Implemented -znotext
gold linker manual describes them as:
-z text Do not permit relocations in read-only segments
-z notext Permit relocations in read-only segments (default)
In LLD default is to not permit them. Patch implements -z notext.
Differential revision: https://reviews.llvm.org/D30530
Added:
lld/trunk/test/ELF/ztext-text-notext.s
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/SyntheticSections.cpp
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=297366&r1=297365&r2=297366&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Thu Mar 9 02:48:34 2017
@@ -142,6 +142,7 @@ struct Configuration {
bool ZNow;
bool ZOrigin;
bool ZRelro;
+ bool ZText;
bool ExitEarly;
bool ZWxneeded;
DiscardPolicy Discard;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=297366&r1=297365&r2=297366&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Mar 9 02:48:34 2017
@@ -599,6 +599,7 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->ZOrigin = hasZOption(Args, "origin");
Config->ZRelro = !hasZOption(Args, "norelro");
Config->ZStackSize = getZOptionValue(Args, "stack-size", 0);
+ Config->ZText = !hasZOption(Args, "notext");
Config->ZWxneeded = hasZOption(Args, "wxneeded");
if (Config->LTOO > 3)
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=297366&r1=297365&r2=297366&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Mar 9 02:48:34 2017
@@ -520,11 +520,12 @@ static RelExpr adjustExpr(const elf::Obj
// only memory. We can hack around it if we are producing an executable and
// the refered symbol can be preemepted to refer to the executable.
if (Config->Shared || (Config->pic() && !isRelExpr(Expr))) {
- error(S.getLocation<ELFT>(RelOff) + ": can't create dynamic relocation " +
- toString(Type) + " against " +
- (Body.getName().empty() ? "local symbol in readonly segment"
- : "symbol '" + toString(Body) + "'") +
- " defined in " + toString(Body.File));
+ if (Config->ZText)
+ error(S.getLocation<ELFT>(RelOff) + ": can't create dynamic relocation " +
+ toString(Type) + " against " +
+ (Body.getName().empty() ? "local symbol in readonly segment"
+ : "symbol '" + toString(Body) + "'") +
+ " defined in " + toString(Body.File));
return Expr;
}
if (Body.getVisibility() != STV_DEFAULT) {
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=297366&r1=297365&r2=297366&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Thu Mar 9 02:48:34 2017
@@ -1111,6 +1111,8 @@ template <class ELFT> void DynamicSectio
add({DT_SYMENT, sizeof(Elf_Sym)});
add({DT_STRTAB, In<ELFT>::DynStrTab});
add({DT_STRSZ, In<ELFT>::DynStrTab->getSize()});
+ if (!Config->ZText)
+ add({DT_TEXTREL, (uint64_t)0});
if (In<ELFT>::GnuHashTab)
add({DT_GNU_HASH, In<ELFT>::GnuHashTab});
if (In<ELFT>::HashTab)
Added: lld/trunk/test/ELF/ztext-text-notext.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ztext-text-notext.s?rev=297366&view=auto
==============================================================================
--- lld/trunk/test/ELF/ztext-text-notext.s (added)
+++ lld/trunk/test/ELF/ztext-text-notext.s Thu Mar 9 02:48:34 2017
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld -z notext %t.o -o %t -shared
+# RUN: llvm-readobj -dynamic-table -r %t | FileCheck %s
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section {{.*}} .rela.dyn {
+# CHECK-NEXT: 0x1000 R_X86_64_RELATIVE - 0x1000
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+# CHECK: DynamicSection [
+# CHECK: 0x0000000000000016 TEXTREL 0x0
+
+foo:
+.quad foo
More information about the llvm-commits
mailing list