https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65859
Bug ID: 65859 Summary: Optimizes out TLS variable called in a child function Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: inline-asm Assignee: unassigned at gcc dot gnu.org Reporter: mike at cchtml dot com Created attachment 35391 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35391&action=edit test case When compiled with -O0 the test case compiles. When compiled with -O1 the test case will not compile with an error for an undefined reference to the TLS variable. If you move the THREAD_VAR_OFFSET macro call to main() gcc will compile without error. Enabling -O1 and turning off optimizations by hand does not change the result. I see the same issue with gcc 4.8, 4.9, and 5.0.