1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-24 00:43:18 +03:00

Add -z interpose

This commit is contained in:
Rui Ueyama 2021-04-10 18:18:56 +09:00
parent ef01e7d7ee
commit 0a62c5c5c6
5 changed files with 25 additions and 0 deletions

View File

@ -374,6 +374,8 @@ void parse_nonpositional_args(Context<E> &ctx,
ctx.arg.z_copyreloc = false;
} else if (read_z_flag(args, "initfirst")) {
ctx.arg.z_initfirst = true;
} else if (read_z_flag(args, "interpose")) {
ctx.arg.z_interpose = true;
} else if (read_flag(args, "no-undefined")) {
ctx.arg.z_defs = true;
} else if (read_flag(args, "fatal-warnings")) {

1
elf.h
View File

@ -184,6 +184,7 @@ static constexpr u32 DF_1_NOW = 0x00000001;
static constexpr u32 DF_1_NODELETE = 0x00000008;
static constexpr u32 DF_1_INITFIRST = 0x00000020;
static constexpr u32 DF_1_NOOPEN = 0x00000040;
static constexpr u32 DF_1_INTERPOSE = 0x00000400;
static constexpr u32 DF_1_PIE = 0x08000000;
static constexpr u32 NT_GNU_BUILD_ID = 3;

1
mold.h
View File

@ -1274,6 +1274,7 @@ struct Context {
bool z_dlopen = true;
bool z_execstack = false;
bool z_initfirst = false;
bool z_interpose = false;
bool z_now = false;
bool z_relro = true;
i16 default_version = VER_NDX_GLOBAL;

View File

@ -482,6 +482,8 @@ static std::vector<typename E::WordTy> create_dynamic_section(Context<E> &ctx) {
flags1 |= DF_1_NODELETE;
if (ctx.arg.z_initfirst)
flags1 |= DF_1_INITFIRST;
if (ctx.arg.z_interpose)
flags1 |= DF_1_INTERPOSE;
if (ctx.has_gottp_rel)
flags |= DF_STATIC_TLS;

19
test/interpose.sh Executable file
View File

@ -0,0 +1,19 @@
#!/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 | clang -c -fPIC -o $t/a.o -xc -
#include <stdio.h>
void foo() {
printf("Hello world\n");
}
EOF
clang -fuse-ld=`pwd`/../mold -shared -o $t/b.so $t/a.o -Wl,-z,interpose
readelf --dynamic $t/b.so | grep -q 'Flags: INTERPOSE'
echo OK