Skip to content

Miscompilation: Missing prefixes for emulatedTLS variables on macOS/ARM64 with -O0 #126200

@sschaller

Description

@sschaller

Reproducer:
https://alive2.llvm.org/ce/z/6Xr9_c

struct T {
    T() {} // required
    int a = 0;
};

thread_local T aa;

int main() {
    return 0;
}

Trying to compile this code on macOS / ARM64 with clang -stdlib=libc++ -std=c++17 -femulated-tls main.cpp
leads to a linker error for undefined symbols ___tls_guard and _aa (4-5, 60-61 in the reproducer).

Inspecting the generated assembly code shows that both symbols are used as operands instead of the prefixed variables ___emutls_v.__tls_guard and ___emutls_v.aa.

Compiling with -O1 correctly prefixes the operands and fixes the issue.

I'm not quite sure what is missing and would appreciate any pointers.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions