1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 10:27:48 +03:00
This commit is contained in:
Rui Ueyama 2020-11-30 17:57:58 +09:00
parent d82f9da125
commit 4d0608d4ca
5 changed files with 24 additions and 1 deletions

View File

@ -796,6 +796,9 @@ int main(int argc, char **argv) {
config.print_map = args.hasArg(OPT_print_map);
config.sysroot = args.getLastArgValue(OPT_sysroot, "");
for (auto *arg : args.filtered(OPT_rpath))
config.rpaths.push_back(arg->getValue());
for (auto *arg : args.filtered(OPT_trace_symbol))
Symbol::intern(arg->getValue())->traced = true;
@ -973,10 +976,14 @@ int main(int argc, char **argv) {
// Beyond this point, no new symbols will be added to the result.
// Copy shared object name strings to .dynsym
// Copy shared object name strings to .dynstr
for (SharedFile *file : out::dsos)
out::dynstr->add_string(file->soname);
// Copy DT_RUNPATH strings to .dynstr.
for (StringRef path : config.rpaths)
out::dynstr->add_string(path);
// Add headers and sections that have to be at the beginning
// or the ending of a file.
out::chunks.insert(out::chunks.begin(), out::ehdr);

1
mold.h
View File

@ -76,6 +76,7 @@ struct Config {
int filler = -1;
std::string sysroot;
std::vector<StringRef> library_paths;
std::vector<StringRef> rpaths;
u64 image_base = 0x200000;
};

View File

@ -44,6 +44,8 @@ def: JoinedOrSeparate<["-"], "y">, Alias<trace_symbol>, HelpText<"Alias for --tr
def as_needed: F<"as-needed">;
def no_as_needed: F<"no-as-needed">;
defm rpath: Eq<"rpath", "Add a DT_RUNPATH to the output">;
def: JoinedOrSeparate<["-"], "z">;
def: F<"hash-style">;
def: J<"hash-style=">;

View File

@ -280,6 +280,9 @@ static std::vector<u64> create_dynamic_section() {
for (SharedFile *file : out::dsos)
define(DT_NEEDED, out::dynstr->find_string(file->soname));
for (StringRef path : config.rpaths)
define(DT_RUNPATH, out::dynstr->find_string(path));
define(DT_RELA, out::reldyn->shdr.sh_addr);
define(DT_RELASZ, out::reldyn->shdr.sh_size);
define(DT_RELAENT, sizeof(ELF64LE::Rela));

10
test/rpath.s Normal file
View File

@ -0,0 +1,10 @@
// RUN: cc -o %t.o -c %s
// RUN: mold -o %t.exe %t.o -rpath /foo -rpath /bar
// RUN: readelf --dynamic %t.exe | FileCheck %s
// CHECK: 0x000000000000001d (RUNPATH) Library runpath: [/foo]
// CHECK: 0x000000000000001d (RUNPATH) Library runpath: [/bar]
.text
.globl _start
_start:
nop