mirror of
https://github.com/rui314/mold.git
synced 2024-10-04 08:37:28 +03:00
[ELF] Define __dso_handle
`cxa_finalize` takes `__dso_handle` to uniquify identify an ELF module in memory. Its actual location doesn't matter but needs to be different for each ELF module. Fixes https://github.com/rui314/mold/issues/507
This commit is contained in:
parent
04efce2d29
commit
764d7575f7
@ -1687,6 +1687,7 @@ struct Context {
|
||||
Symbol<E> *_TLS_MODULE_BASE_ = nullptr;
|
||||
Symbol<E> *__GNU_EH_FRAME_HDR = nullptr;
|
||||
Symbol<E> *__bss_start = nullptr;
|
||||
Symbol<E> *__dso_handle = nullptr;
|
||||
Symbol<E> *__ehdr_start = nullptr;
|
||||
Symbol<E> *__executable_start = nullptr;
|
||||
Symbol<E> *__exidx_end = nullptr;
|
||||
|
@ -391,6 +391,7 @@ ObjectFile<E> *create_internal_file(Context<E> &ctx) {
|
||||
ctx._etext = add("_etext");
|
||||
ctx._edata = add("_edata");
|
||||
ctx.__executable_start = add("__executable_start");
|
||||
ctx.__dso_handle = add("__dso_handle");
|
||||
|
||||
ctx.__rel_iplt_start =
|
||||
add(E::is_rel ? "__rel_iplt_start" : "__rela_iplt_start");
|
||||
@ -1457,7 +1458,7 @@ void fix_synthetic_symbols(Context<E> &ctx) {
|
||||
if (Chunk<E> *chunk = find(".bss"))
|
||||
start(ctx.__bss_start, chunk);
|
||||
|
||||
// __ehdr_start and __executable_start
|
||||
// __ehdr_start, __executable_start and __dso_handle
|
||||
if (ctx.ehdr) {
|
||||
for (Chunk<E> *chunk : ctx.chunks) {
|
||||
if (chunk->shndx == 1) {
|
||||
@ -1465,6 +1466,8 @@ void fix_synthetic_symbols(Context<E> &ctx) {
|
||||
ctx.__ehdr_start->value = ctx.ehdr->shdr.sh_addr;
|
||||
ctx.__executable_start->shndx = -1;
|
||||
ctx.__executable_start->value = ctx.ehdr->shdr.sh_addr;
|
||||
ctx.__dso_handle->shndx = -1;
|
||||
ctx.__dso_handle->value = ctx.ehdr->shdr.sh_addr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ cat <<EOF | $CC -c -o $t/b.o -xc -
|
||||
|
||||
extern char __ehdr_start[];
|
||||
extern char __executable_start[];
|
||||
extern char __dso_handle[];
|
||||
extern char _end[];
|
||||
extern char end[];
|
||||
extern char _etext[];
|
||||
@ -48,6 +49,7 @@ int main() {
|
||||
|
||||
printf("__ehdr_start=%p\n", &__ehdr_start);
|
||||
printf("__executable_start=%p\n", &__executable_start);
|
||||
printf("__dso_handle=%p\n", &__dso_handle);
|
||||
printf("%.*s\n", (int)(__stop_foo - __start_foo), __start_foo);
|
||||
}
|
||||
EOF
|
||||
@ -69,6 +71,7 @@ cat <<EOF | $CC -c -o $t/c.o -xc -
|
||||
|
||||
char __ehdr_start[] = "foo";
|
||||
char __executable_start[] = "foo";
|
||||
char __dso_handle[] = "foo";
|
||||
char _end[] = "foo";
|
||||
char end[] = "foo";
|
||||
char _etext[] = "foo";
|
||||
@ -92,6 +95,7 @@ int main() {
|
||||
|
||||
printf("__ehdr_start=%p\n", &__ehdr_start);
|
||||
printf("__executable_start=%p\n", &__executable_start);
|
||||
printf("__dso_handle=%p\n", &__dso_handle);
|
||||
printf("%.*s\n", (int)(__stop_foo - __start_foo), __start_foo);
|
||||
}
|
||||
EOF
|
||||
@ -104,6 +108,7 @@ grep -q '^etext=foo$' $t/log
|
||||
grep -q '^edata=foo$' $t/log
|
||||
grep -q '^__ehdr_start=0x40000$' $t/log
|
||||
grep -q '^__executable_start=0x40000$' $t/log
|
||||
grep -q '^__dso_handle=0x40000$' $t/log
|
||||
grep -q '^section foo$' $t/log
|
||||
|
||||
echo OK
|
||||
|
Loading…
Reference in New Issue
Block a user