From cebb449e114deebdffdc438049870105240f162e Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Tue, 13 Oct 2015 21:02:34 +0000 Subject: [PATCH] [ELF2] Add support for -Bsymbolic. llvm-svn: 250225 --- lld/ELF/Config.h | 1 + lld/ELF/Driver.cpp | 1 + lld/ELF/Options.td | 3 +++ lld/ELF/OutputSections.cpp | 11 +++++++++-- lld/test/elf2/{now.s => dt_flags.s} | 12 ++++++------ 5 files changed, 20 insertions(+), 8 deletions(-) rename lld/test/elf2/{now.s => dt_flags.s} (62%) diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 0ba9671434b2..bac8382f477d 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -44,6 +44,7 @@ struct Configuration { std::vector SearchPaths; bool AllowMultipleDefinition; bool AsNeeded = false; + bool Bsymbolic; bool DiscardAll; bool DiscardLocals; bool DiscardNone; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 0c9ab316ecc1..53be66c55f11 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -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); diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td index 20f34acab275..794fc93c3559 100644 --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -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">; diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 265bf94afd88..5077f58cd2f7 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -293,8 +293,10 @@ template void DynamicSection::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 void DynamicSection::writeTo(uint8_t *Buf) { if (FiniSym) WritePtr(DT_FINI, getSymVA(*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); } diff --git a/lld/test/elf2/now.s b/lld/test/elf2/dt_flags.s similarity index 62% rename from lld/test/elf2/now.s rename to lld/test/elf2/dt_flags.s index 64c37e781779..b98149d5280e 100644 --- a/lld/test/elf2/now.s +++ b/lld/test/elf2/dt_flags.s @@ -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