[ELF2] Add support for -z origin.

llvm-svn: 250907
This commit is contained in:
Davide Italiano 2015-10-21 17:09:47 +00:00
parent e3bf4fd546
commit 6e91c598b9
4 changed files with 14 additions and 7 deletions

View File

@ -59,6 +59,7 @@ struct Configuration {
bool Verbose;
bool ZNodelete = false;
bool ZNow = false;
bool ZOrigin = false;
ELFKind EKind = ELFNoneKind;
uint16_t EMachine = llvm::ELF::EM_NONE;
uint64_t EntryAddr = -1;

View File

@ -163,6 +163,8 @@ void LinkerDriver::createFiles(opt::InputArgList &Args) {
Config->ZNodelete = true;
else if (Arg->getValue() == StringRef("now"))
Config->ZNow = true;
else if (Arg->getValue() == StringRef("origin"))
Config->ZOrigin = true;
}
for (auto *Arg : Args) {

View File

@ -349,9 +349,9 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() {
++NumEntries; // DT_INIT
if (FiniSym)
++NumEntries; // DT_FINI
if (Config->Bsymbolic || Config->ZNow)
if (Config->Bsymbolic || Config->ZNow || Config->ZOrigin)
++NumEntries; // DT_FLAGS
if (Config->ZNodelete || Config->ZNow)
if (Config->ZNodelete || Config->ZNow || Config->ZOrigin)
++NumEntries; // DT_FLAGS_1
++NumEntries; // DT_NULL
@ -434,6 +434,8 @@ template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {
Flags |= DF_SYMBOLIC;
if (Config->ZNow)
Flags |= DF_BIND_NOW;
if (Config->ZOrigin)
Flags |= DF_ORIGIN;
if (Flags)
WriteVal(DT_FLAGS, Flags);
Flags = 0;
@ -441,6 +443,8 @@ template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {
Flags |= DF_1_NODELETE;
if (Config->ZNow)
Flags |= DF_1_NOW;
if (Config->ZOrigin)
Flags |= DF_1_ORIGIN;
if (Flags)
WriteVal(DT_FLAGS_1, Flags);

View File

@ -2,19 +2,19 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld2 -shared %t -o %t.so
# RUN: ld.lld2 -z now -z nodelete -Bsymbolic %t %t.so -o %t1
# RUN: ld.lld2 -z now -z nodelete -z origin -Bsymbolic %t %t.so -o %t1
# RUN: ld.lld2 %t %t.so -o %t2
# RUN: llvm-readobj -dynamic-table %t1 | FileCheck -check-prefix=FLAGS %s
# RUN: llvm-readobj -dynamic-table %t2 | FileCheck %s
# FLAGS: DynamicSection [
# FLAGS: 0x000000000000001E FLAGS SYMBOLIC BIND_NOW
# FLAGS: 0x000000006FFFFFFB FLAGS_1 NOW NODELETE
# FLAGS: 0x000000000000001E FLAGS ORIGIN SYMBOLIC BIND_NOW
# FLAGS: 0x000000006FFFFFFB FLAGS_1 NOW NODELETE ORIGIN
# FLAGS: ]
# CHECK: DynamicSection [
# CHECK-NOT: 0x000000000000001E FLAGS SYMBOLIC BIND_NOW
# CHECK-NOT: 0x000000006FFFFFFB FLAGS_1 NOW NODELETE
# CHECK-NOT: 0x000000000000001E FLAGS ORIGIN SYMBOLIC BIND_NOW
# CHECK-NOT: 0x000000006FFFFFFB FLAGS_1 NOW NODELETE ORIGIN
# CHECK: ]
.globl _start