[ELF2] Add support for -Bsymbolic.

llvm-svn: 250225
This commit is contained in:
Davide Italiano 2015-10-13 21:02:34 +00:00
parent 7f08d80595
commit cebb449e11
5 changed files with 20 additions and 8 deletions

View File

@ -44,6 +44,7 @@ struct Configuration {
std::vector<llvm::StringRef> SearchPaths;
bool AllowMultipleDefinition;
bool AsNeeded = false;
bool Bsymbolic;
bool DiscardAll;
bool DiscardLocals;
bool DiscardNone;

View File

@ -136,6 +136,7 @@ void LinkerDriver::createFiles(opt::InputArgList &Args) {
}
Config->AllowMultipleDefinition = Args.hasArg(OPT_allow_multiple_definition);
Config->Bsymbolic = Args.hasArg(OPT_Bsymbolic);
Config->DiscardAll = Args.hasArg(OPT_discard_all);
Config->DiscardLocals = Args.hasArg(OPT_discard_locals);
Config->DiscardNone = Args.hasArg(OPT_discard_none);

View File

@ -1,5 +1,8 @@
include "llvm/Option/OptParser.td"
def Bsymbolic: Flag<["-"], "Bsymbolic">,
HelpText<"Bind defined symbols locally">;
def Bdynamic: Flag<["-"], "Bdynamic">,
HelpText<"Link against shared libraries">;

View File

@ -293,8 +293,10 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() {
++NumEntries; // DT_INIT
if (FiniSym)
++NumEntries; // DT_FINI
if (Config->ZNow)
if (Config->ZNow || Config->Bsymbolic)
++NumEntries; // DT_FLAGS_1
if (Config->Bsymbolic)
++NumEntries; // DT_SYMBOLIC
++NumEntries; // DT_NULL
@ -366,8 +368,13 @@ template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {
if (FiniSym)
WritePtr(DT_FINI, getSymVA<ELFT>(*FiniSym));
uint32_t Flags = 0;
if (Config->Bsymbolic)
Flags |= DF_SYMBOLIC;
if (Config->ZNow)
WriteVal(DT_FLAGS_1, DF_1_NOW);
Flags |= DF_1_NOW;
if (Flags)
WriteVal(DT_FLAGS_1, Flags);
WriteVal(DT_NULL, 0);
}

View File

@ -2,17 +2,17 @@
# 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 %t %t.so -o %t1
# RUN: ld.lld2 -z now -Bsymbolic %t %t.so -o %t1
# RUN: ld.lld2 %t %t.so -o %t2
# RUN: llvm-readobj -dynamic-table %t1 | FileCheck -check-prefix=NOW %s
# RUN: llvm-readobj -dynamic-table %t1 | FileCheck -check-prefix=FLAGS %s
# RUN: llvm-readobj -dynamic-table %t2 | FileCheck %s
# NOW: DynamicSection [
# NOW: 0x000000006FFFFFFB FLAGS_1 NOW
# NOW: ]
# FLAGS: DynamicSection [
# FLAGS: 0x000000006FFFFFFB FLAGS_1 NOW GLOBAL
# FLAGS: ]
# CHECK: DynamicSection [
# CHECK-NOT: 0x000000006FFFFFFB FLAGS_1 NOW
# CHECK-NOT: 0x000000006FFFFFFB FLAGS_1 NOW GLOBAL
# CHECK: ]
.globl _start