Skip to content

Instantly share code, notes, and snippets.

@tea
Created July 2, 2024 02:57
Show Gist options
  • Save tea/e5b14d4023a4034bc5ab68315b8544bd to your computer and use it in GitHub Desktop.
Save tea/e5b14d4023a4034bc5ab68315b8544bd to your computer and use it in GitHub Desktop.
Redox TLS difference
$ cat test.c
static int __thread x = 0;
int main(void) {
x++;
}
$ riscv64-linux-gnu-objdump -dr test.o
test.o: file format elf64-littleriscv
Disassembly of section .text.startup:
0000000000000000 <main>:
0: 00000517 auipc a0,0x0
0: R_RISCV_TLS_GD_HI20 .LANCHOR0
4: 00050513 mv a0,a0
4: R_RISCV_PCREL_LO12_I .L0
4: R_RISCV_RELAX *ABS*
8: 1141 addi sp,sp,-16
a: e406 sd ra,8(sp)
c: 00000097 auipc ra,0x0
c: R_RISCV_CALL_PLT __tls_get_addr
c: R_RISCV_RELAX *ABS*
10: 000080e7 jalr ra # c <main+0xc>
14: 4118 lw a4,0(a0)
16: 60a2 ld ra,8(sp)
18: 87aa mv a5,a0
1a: 2705 addiw a4,a4,1
1c: c398 sw a4,0(a5)
1e: 4501 li a0,0
20: 0141 addi sp,sp,16
22: 8082 ret
$ riscv64-linux-gnu-objdump -sr test.o
test.o: file format elf64-littleriscv
RELOCATION RECORDS FOR [.text.startup]:
OFFSET TYPE VALUE
0000000000000000 R_RISCV_TLS_GD_HI20 .LANCHOR0
0000000000000004 R_RISCV_PCREL_LO12_I .L0
0000000000000004 R_RISCV_RELAX *ABS*
000000000000000c R_RISCV_CALL_PLT __tls_get_addr
000000000000000c R_RISCV_RELAX *ABS*
$ riscv64-linux-gnu-gcc -o test_linux test.o
$ riscv64-linux-gnu-objdump -dr test_linux
...
0000000000000650 <main>:
650: 00002517 auipc a0,0x2
654: 9e050513 addi a0,a0,-1568 # 2030 <_GLOBAL_OFFSET_TABLE_+0x8>
658: 1141 addi sp,sp,-16
65a: e406 sd ra,8(sp)
65c: fe5ff0ef jal ra,640 <__tls_get_addr@plt>
...
$ riscv64-linux-gnu-objdump -sr test_linux
...
Contents of section .got:
2030 00000000 00000000 00f8ffff ffffffff
...
$ riscv64-unknown-redox-gcc -o test_redox test.o
$ riscv64-linux-gnu-objdump -dr test_redox
...
00000000000123c0 <main>:
123c0: 00105517 auipc a0,0x105
123c4: df050513 addi a0,a0,-528 # 1171b0 <_GLOBAL_OFFSET_TABLE_+0x8>
123c8: 1141 addi sp,sp,-16
123ca: e406 sd ra,8(sp)
123cc: 313210ef jal ra,33ede <__tls_get_addr>
...
$ riscv64-linux-gnu-objdump -sr test_redox
...
1171b0 01000000 00000000 08f8ffff ffffffff
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment