forked from OSchip/llvm-project
[ELF2] -z now option implemented
When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is started, or when the shared library is linked to using dlopen, instead of deferring function call resolution to the point when the function is first called. Differential Revision: http://reviews.llvm.org/D13468 llvm-svn: 249551
This commit is contained in:
parent
aebca09543
commit
97aad172b8
|
@ -44,6 +44,7 @@ struct Configuration {
|
|||
bool ExportDynamic;
|
||||
bool NoInhibitExec;
|
||||
bool NoUndefined;
|
||||
bool ZNow = false;
|
||||
bool Shared;
|
||||
bool Static = false;
|
||||
bool WholeArchive = false;
|
||||
|
|
|
@ -186,6 +186,11 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
|
|||
Config->NoUndefined = Args.hasArg(OPT_no_undefined);
|
||||
Config->Shared = Args.hasArg(OPT_shared);
|
||||
|
||||
for (auto *Arg : Args.filtered(OPT_z)) {
|
||||
if (Arg->getValue() == StringRef("now"))
|
||||
Config->ZNow = true;
|
||||
}
|
||||
|
||||
for (auto *Arg : Args) {
|
||||
switch (Arg->getOption().getID()) {
|
||||
case OPT_l:
|
||||
|
|
|
@ -82,6 +82,9 @@ def undefined : Joined<["--"], "undefined=">,
|
|||
def whole_archive : Flag<["--"], "whole-archive">,
|
||||
HelpText<"Force load of all members in a static library">;
|
||||
|
||||
def z : JoinedOrSeparate<["-"], "z">, MetaVarName<"<option>">,
|
||||
HelpText<"Linker option extensions">;
|
||||
|
||||
// Aliases
|
||||
def alias_Bdynamic_call_shared: Flag<["-"], "call_shared">, Alias<Bdynamic>;
|
||||
def alias_Bdynamic_dy: Flag<["-"], "dy">, Alias<Bdynamic>;
|
||||
|
@ -114,4 +117,3 @@ def no_fatal_warnings : Flag<["--"], "no-fatal-warnings">;
|
|||
def start_group : Flag<["--"], "start-group">;
|
||||
def strip_all : Flag<["--"], "strip-all">;
|
||||
def version_script : Separate<["--"], "version-script">;
|
||||
def z : Separate<["-"], "z">;
|
||||
|
|
|
@ -269,6 +269,8 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() {
|
|||
++NumEntries; // DT_INIT
|
||||
if (FiniSym)
|
||||
++NumEntries; // DT_FINI
|
||||
if (Config->ZNow)
|
||||
++NumEntries; // DT_FLAGS_1
|
||||
|
||||
++NumEntries; // DT_NULL
|
||||
|
||||
|
@ -341,6 +343,9 @@ template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {
|
|||
if (FiniSym)
|
||||
WritePtr(DT_FINI, getSymVA(*FiniSym, BssSec));
|
||||
|
||||
if (Config->ZNow)
|
||||
WriteVal(DT_FLAGS_1, DF_1_NOW);
|
||||
|
||||
WriteVal(DT_NULL, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# REQUIRES: x86
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
|
||||
# RUN: lld -flavor gnu2 -shared %t -o %t.so
|
||||
# RUN: lld -flavor gnu2 -z now %t %t.so -o %t1
|
||||
# RUN: lld -flavor gnu2 %t %t.so -o %t2
|
||||
# RUN: llvm-readobj -dynamic-table %t1 | FileCheck -check-prefix=NOW %s
|
||||
# RUN: llvm-readobj -dynamic-table %t2 | FileCheck %s
|
||||
|
||||
# NOW: DynamicSection [
|
||||
# NOW: 0x000000006FFFFFFB FLAGS_1 NOW
|
||||
# NOW: ]
|
||||
|
||||
# CHECK: DynamicSection [
|
||||
# CHECK-NOT: 0x000000006FFFFFFB FLAGS_1 NOW
|
||||
# CHECK: ]
|
||||
|
||||
.globl _start
|
||||
_start:
|
Loading…
Reference in New Issue