https://bugs.llvm.org/show_bug.cgi?id=46297

            Bug ID: 46297
           Summary: IR Linking of GlobalAliases does not preserve
                    thread_local attribute
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Core LLVM classes
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

When trying to compile the following code under LTO with a low optimization
level (--lto-O0, for instance), a link error is encountered (relative
relocation against absolute symbol).
This is a bug in the IR linking process whereby the ThreadLocalMode attribute
of GlobalAliases is not copied properly. The bug is masked in higher
optimization levels (uncomment --lto-O2) due to GlobalAlias resolution (uses of
the alias are replaced with uses of the aliasee).

May be related to PR33846.

//
// main.c
//
#define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))

extern __thread int tlsvar attribute_tls_model_ie;
extern __thread int tlsvar2 attribute_tls_model_ie;

void foo()
{
        tlsvar2 = 5;
}

//
// tlsvar.c
//
#define attribute_hidden __attribute__ ((visibility ("hidden")))
#define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))

__thread int tlsvar attribute_tls_model_ie;
extern __thread int tlsvar2 __attribute__ ((alias ("tlsvar")))
  attribute_hidden attribute_tls_model_ie;

//
// build.sh
//
#!/bin/bash -eu

_CC="clang-10"
_LTO_OPT="-Xlinker --lto-O0"
#_LTO_OPT="-Xlinker --lto-O2"

${_CC} -fPIC -flto -c main.c -o main.c.o
${_CC} -fPIC -flto -c tlsvar.c -o tlsvar.c.o
${_CC} -fPIC -flto -shared ${_LTO_OPT} -fuse-ld=lld main.c.o tlsvar.c.o -o main

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to