1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-15 14:36:25 +03:00

Add "-z nocopyreloc"

This commit is contained in:
Rui Ueyama 2021-03-18 19:54:56 +09:00
parent b96155dafa
commit 1131ea7512
4 changed files with 39 additions and 0 deletions

View File

@ -305,6 +305,8 @@ void parse_nonpositional_args(std::span<std::string_view> args,
config.z_dlopen = false;
} else if (read_z_flag(args, "nodelete")) {
config.z_delete = false;
} else if (read_z_flag(args, "nocopyreloc")) {
config.z_copyreloc = false;
} else if (read_flag(args, "no-undefined")) {
config.z_defs = true;
} else if (read_flag(args, "fork")) {

View File

@ -509,6 +509,8 @@ void InputSection::scan_relocations() {
case ERROR:
break;
case COPYREL:
if (!config.z_copyreloc)
break;
sym.flags |= NEEDS_COPYREL;
rel_types[i] = rel_type;
return;

2
mold.h
View File

@ -89,6 +89,7 @@ struct Config {
bool strip_all = false;
bool strip_debug = false;
bool trace = false;
bool z_copyreloc = true;
bool z_defs = false;
bool z_delete = true;
bool z_dlopen = true;
@ -1257,6 +1258,7 @@ inline std::vector<ObjectFile *> objs;
inline std::vector<SharedFile *> dsos;
inline std::vector<OutputChunk *> chunks;
inline std::atomic_bool df_static_tls = false;
inline std::atomic_bool has_textrel = false;
inline ObjectFile *internal_obj;
inline OutputEhdr *ehdr;

33
test/nocopyreloc.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
set -e
cd $(dirname $0)
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/tmp/$(basename -s .sh $0)
mkdir -p $t
cat <<EOF | cc -shared -o $t/a.so -xc -
int foo = 3;
int bar = 5;
EOF
cat <<EOF | cc -fno-PIC -c -o $t/b.o -xc -
#include <stdio.h>
extern int foo;
extern int bar;
int main() {
printf("%d %d\n", foo, bar);
return 0;
}
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/a.so $t/b.o
$t/exe | grep -q '3 5'
! clang -fuse-ld=`pwd`/../mold -o $t/exe $t/a.so $t/b.o \
-Wl,-z,nocopyreloc 2> $t/log
grep -q 'recompile with -fPIE' $t/log
echo OK