This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Implement TLSDESC for x86-32
ClosedPublic

Authored by MaskRay on Oct 26 2021, 4:57 PM.

Details

Summary

-z rela is also supported.

Tested with:

cat > ./a.c <<eof
#include <assert.h>
int foo();
int bar();
int main() {
  assert(foo() == 2);
  assert(foo() == 4);
  assert(bar() == 2);
  assert(bar() == 4);
}
eof

cat > ./b.c <<eof
#include <stdio.h>
__thread int tls0;
extern __thread int tls1;
int foo() { return ++tls0 + ++tls1; }
static __thread int tls2, tls3;
int bar() { return ++tls2 + ++tls3; }
eof

echo '__thread int tls1;' > ./c.c

sed 's/        /\t/' > ./Makefile <<'eof'
.MAKE.MODE = meta curDirOk=true

CC := gcc -m32 -g -fpic -mtls-dialect=gnu2
LDFLAGS := -m32 -Wl,-rpath=.

all: a0 a1 a2

run: all
        ./a0 && ./a1 && ./a2

c.so: c.o; ${LINK.c} -shared $> -o $@
bc.so: b.o c.o; ${LINK.c} -shared $> -o $@
b.so: b.o c.so; ${LINK.c} -shared $> -o $@

a0: a.o b.o c.o; ${LINK.c} $> -o $@
a1: a.o b.so; ${LINK.c} $> -o $@
a2: a.o bc.so; ${LINK.c} $> -o $@
eof

and glibc elf/tst-gnu2-tls1.

/usr/local/bin/ld points to the freshly built lld.

bmake run && bmake CFLAGS=-O1 run => ok.

Diff Detail

Event Timeline

MaskRay created this revision.Oct 26 2021, 4:57 PM
MaskRay requested review of this revision.Oct 26 2021, 4:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 26 2021, 4:58 PM
MaskRay updated this revision to Diff 382505.Oct 26 2021, 6:57 PM
MaskRay retitled this revision from [ELF] Implement General Dynamic style TLSDESC for x86-32 to [ELF] Implement TLSDESC for x86-32.
MaskRay edited the summary of this revision. (Show Details)

Support Local Dynamic style TLSDESC

Improve test (--no-apply-dynamic-relocs)

MaskRay updated this revision to Diff 382511.Oct 26 2021, 7:55 PM

improve test

MaskRay updated this revision to Diff 382512.Oct 26 2021, 8:02 PM
MaskRay edited the summary of this revision. (Show Details)

improve tests

MaskRay accepted this revision.Oct 28 2021, 5:46 PM
MaskRay edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Oct 28 2021, 5:46 PM
This revision was landed with ongoing or failed builds.Oct 28 2021, 5:52 PM
This revision was automatically updated to reflect the committed changes.