Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/rt/sections_elf_shared.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static if (SharedELF):

// debug = PRINTF;
import core.memory;
import core.stdc.config;
import core.stdc.stdio;
import core.stdc.stdlib : calloc, exit, free, malloc, EXIT_FAILURE;
import core.stdc.string : strlen;
Expand Down Expand Up @@ -906,8 +907,27 @@ version (Shared) void* handleForAddr(void* addr) nothrow @nogc
*/
struct tls_index
{
size_t ti_module;
size_t ti_offset;
version (CRuntime_Glibc)
{
// For x86_64, fields are of type uint64_t, this is important for x32
// where tls_index would otherwise have the wrong size.
// See https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/dl-tls.h
version (X86_64)
{
ulong ti_module;
ulong ti_offset;
}
else
{
c_ulong ti_module;
c_ulong ti_offset;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've verified that in other cases ti_module & ti_offset are unsigned long int.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, just for the discussion thread, I left size_t in as the default branch. At least musl defines this as a size_t[2] type.

(Grep'ing musl 1.16 for __tls__get_addr):

void *__tls_get_addr(size_t *);
...
return __tls_get_addr((size_t []){def.dso->tls_id, def.sym->st_value});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "other cases" I meant only by grepping the source of glibc. I didn't mean for musl etc.

}
}
else
{
size_t ti_module;
size_t ti_offset;
}
}

extern(C) void* __tls_get_addr(tls_index* ti) nothrow @nogc;
Expand Down