ELF2: Add -soname option.

llvm-svn: 249058
This commit is contained in:
Rui Ueyama 2015-10-01 19:36:04 +00:00
parent f14b3f10a8
commit 7de3f3719a
5 changed files with 31 additions and 6 deletions

View File

@ -21,6 +21,7 @@ struct Configuration {
llvm::StringRef DynamicLinker; llvm::StringRef DynamicLinker;
llvm::StringRef Entry; llvm::StringRef Entry;
llvm::StringRef OutputFile = "a.out"; llvm::StringRef OutputFile = "a.out";
llvm::StringRef SoName;
llvm::StringRef Sysroot; llvm::StringRef Sysroot;
std::string RPath; std::string RPath;
std::vector<llvm::StringRef> InputSearchPaths; std::vector<llvm::StringRef> InputSearchPaths;

View File

@ -117,6 +117,9 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
if (auto *Arg = Args.getLastArg(OPT_entry)) if (auto *Arg = Args.getLastArg(OPT_entry))
Config->Entry = Arg->getValue(); Config->Entry = Arg->getValue();
if (auto *Arg = Args.getLastArg(OPT_soname))
Config->SoName = Arg->getValue();
Config->AllowMultipleDefinition = Args.hasArg(OPT_allow_multiple_definition); Config->AllowMultipleDefinition = Args.hasArg(OPT_allow_multiple_definition);
Config->DiscardAll = Args.hasArg(OPT_discard_all); Config->DiscardAll = Args.hasArg(OPT_discard_all);
Config->DiscardLocals = Args.hasArg(OPT_discard_locals); Config->DiscardLocals = Args.hasArg(OPT_discard_locals);

View File

@ -52,6 +52,9 @@ def rpath : Separate<["-"], "rpath">,
def shared : Flag<["-"], "shared">, def shared : Flag<["-"], "shared">,
HelpText<"Build a shared object">; HelpText<"Build a shared object">;
def soname : Joined<["-"], "soname=">,
HelpText<"Set DT_SONAME">;
def sysroot : Joined<["--"], "sysroot=">, def sysroot : Joined<["--"], "sysroot=">,
HelpText<"Set the system root">; HelpText<"Set the system root">;
@ -69,6 +72,7 @@ def alias_discard_all: Flag<["-"], "x">, Alias<discard_all>;
def alias_discard_locals: Flag<["-"], "X">, Alias<discard_locals>; def alias_discard_locals: Flag<["-"], "X">, Alias<discard_locals>;
def alias_entry : Separate<["-"], "e">, Alias<entry>; def alias_entry : Separate<["-"], "e">, Alias<entry>;
def alias_l : Joined<["--"], "library=">, Alias<l>; def alias_l : Joined<["--"], "library=">, Alias<l>;
def alias_soname : Separate<["-"], "h">, Alias<soname>;
// Options listed below are silently ignored now. // Options listed below are silently ignored now.
def as_needed : Flag<["--"], "as-needed">; def as_needed : Flag<["--"], "as-needed">;

View File

@ -198,10 +198,14 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() {
++NumEntries; // DT_STRSZ ++NumEntries; // DT_STRSZ
++NumEntries; // DT_HASH ++NumEntries; // DT_HASH
StringRef RPath = Config->RPath; if (!Config->RPath.empty()) {
if (!RPath.empty()) {
++NumEntries; // DT_RUNPATH ++NumEntries; // DT_RUNPATH
DynStrSec.add(RPath); DynStrSec.add(Config->RPath);
}
if (!Config->SoName.empty()) {
++NumEntries; // DT_SONAME
DynStrSec.add(Config->SoName);
} }
const std::vector<std::unique_ptr<SharedFileBase>> &SharedFiles = const std::vector<std::unique_ptr<SharedFileBase>> &SharedFiles =
@ -255,10 +259,15 @@ template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {
P->d_un.d_ptr = HashSec.getVA(); P->d_un.d_ptr = HashSec.getVA();
++P; ++P;
StringRef RPath = Config->RPath; if (!Config->RPath.empty()) {
if (!RPath.empty()) {
P->d_tag = DT_RUNPATH; P->d_tag = DT_RUNPATH;
P->d_un.d_val = DynStrSec.getFileOff(RPath); P->d_un.d_val = DynStrSec.getFileOff(Config->RPath);
++P;
}
if (!Config->SoName.empty()) {
P->d_tag = DT_SONAME;
P->d_un.d_val = DynStrSec.getFileOff(Config->SoName);
++P; ++P;
} }

8
lld/test/elf2/soname2.s Normal file
View File

@ -0,0 +1,8 @@
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: lld -flavor gnu2 %t.o -shared -soname=foo.so -o %t
// RUN: llvm-readobj --dynamic-table %t | FileCheck %s
// CHECK: 0x000000000000000E SONAME LibrarySoname (foo.so)
.global _start
_start: