https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121318
Bug ID: 121318
Summary: handle_tls_model_attribute failed to consider compiler
options
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: hjl.tools at gmail dot com
Target Milestone: ---
[hjl@gnu-cfl-3 tls-1]$ cat b4.c
extern const int afoo[3];
__thread const int *pfoo __attribute__ ((tls_model ("initial-exec"))) = afoo;
const int **
ppfoo (void)
{
return &pfoo;
}
[hjl@gnu-cfl-3 tls-1]$ gcc -O3 -fPIE -ftls-model=initial-exec -S b4.c
[hjl@gnu-cfl-3 tls-1]$ cat b4.s
.file "b4.c"
.text
.p2align 4
.globl ppfoo
.type ppfoo, @function
ppfoo:
.LFB0:
.cfi_startproc
movq pfoo@gottpoff(%rip), %rax
addq %fs:0, %rax
ret
.cfi_endproc
.LFE0:
.size ppfoo, .-ppfoo
.globl pfoo
.section .tdata,"awT",@progbits
.align 8
.type pfoo, @object
.size pfoo, 8
pfoo:
.quad afoo
.ident "GCC: (GNU) 15.1.1 20250521 (Red Hat 15.1.1-2)"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-cfl-3 tls-1]$
Since pfoo is defined locally, TLS_MODEL_LOCAL_EXEC should be used even with
__attribute__ ((tls_model ("initial-exec"))). The expected code is
ppfoo:
.LFB0:
.cfi_startproc
movq %fs:0, %rax
addq $pfoo@tpoff, %rax
ret
.cfi_endproc