1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-21 09:57:18 +03:00

Add -z initfirst

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

View File

@ -372,6 +372,8 @@ void parse_nonpositional_args(Context<E> &ctx,
ctx.arg.z_delete = false;
} else if (read_z_flag(args, "nocopyreloc")) {
ctx.arg.z_copyreloc = false;
} else if (read_z_flag(args, "initfirst")) {
ctx.arg.z_initfirst = 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

@ -182,6 +182,7 @@ static constexpr u32 DF_STATIC_TLS = 0x10;
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_PIE = 0x08000000;

1
mold.h
View File

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

View File

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

19
test/initfirst.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,initfirst
readelf --dynamic $t/b.so | grep -q 'Flags: INITFIRST'
echo OK