[lld] r249058 - ELF2: Add -soname option.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 12:36:05 PDT 2015
Author: ruiu
Date: Thu Oct 1 14:36:04 2015
New Revision: 249058
URL: http://llvm.org/viewvc/llvm-project?rev=249058&view=rev
Log:
ELF2: Add -soname option.
Added:
lld/trunk/test/elf2/soname2.s
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Options.td
lld/trunk/ELF/OutputSections.cpp
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=249058&r1=249057&r2=249058&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Thu Oct 1 14:36:04 2015
@@ -21,6 +21,7 @@ struct Configuration {
llvm::StringRef DynamicLinker;
llvm::StringRef Entry;
llvm::StringRef OutputFile = "a.out";
+ llvm::StringRef SoName;
llvm::StringRef Sysroot;
std::string RPath;
std::vector<llvm::StringRef> InputSearchPaths;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=249058&r1=249057&r2=249058&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Oct 1 14:36:04 2015
@@ -117,6 +117,9 @@ void LinkerDriver::link(ArrayRef<const c
if (auto *Arg = Args.getLastArg(OPT_entry))
Config->Entry = Arg->getValue();
+ if (auto *Arg = Args.getLastArg(OPT_soname))
+ Config->SoName = Arg->getValue();
+
Config->AllowMultipleDefinition = Args.hasArg(OPT_allow_multiple_definition);
Config->DiscardAll = Args.hasArg(OPT_discard_all);
Config->DiscardLocals = Args.hasArg(OPT_discard_locals);
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=249058&r1=249057&r2=249058&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Thu Oct 1 14:36:04 2015
@@ -52,6 +52,9 @@ def rpath : Separate<["-"], "rpath">,
def shared : Flag<["-"], "shared">,
HelpText<"Build a shared object">;
+def soname : Joined<["-"], "soname=">,
+ HelpText<"Set DT_SONAME">;
+
def sysroot : Joined<["--"], "sysroot=">,
HelpText<"Set the system root">;
@@ -69,6 +72,7 @@ def alias_discard_all: Flag<["-"], "x">,
def alias_discard_locals: Flag<["-"], "X">, Alias<discard_locals>;
def alias_entry : Separate<["-"], "e">, Alias<entry>;
def alias_l : Joined<["--"], "library=">, Alias<l>;
+def alias_soname : Separate<["-"], "h">, Alias<soname>;
// Options listed below are silently ignored now.
def as_needed : Flag<["--"], "as-needed">;
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=249058&r1=249057&r2=249058&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Oct 1 14:36:04 2015
@@ -198,10 +198,14 @@ template <class ELFT> void DynamicSectio
++NumEntries; // DT_STRSZ
++NumEntries; // DT_HASH
- StringRef RPath = Config->RPath;
- if (!RPath.empty()) {
+ if (!Config->RPath.empty()) {
++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 =
@@ -255,10 +259,15 @@ template <class ELFT> void DynamicSectio
P->d_un.d_ptr = HashSec.getVA();
++P;
- StringRef RPath = Config->RPath;
- if (!RPath.empty()) {
+ if (!Config->RPath.empty()) {
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;
}
Added: lld/trunk/test/elf2/soname2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/soname2.s?rev=249058&view=auto
==============================================================================
--- lld/trunk/test/elf2/soname2.s (added)
+++ lld/trunk/test/elf2/soname2.s Thu Oct 1 14:36:04 2015
@@ -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:
More information about the llvm-commits
mailing list