[llvm-bugs] [Bug 46297] New: IR Linking of GlobalAliases does not preserve thread_local attribute

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jun 12 01:49:31 PDT 2020


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: unassignedbugs at nondot.org
          Reporter: itay.bookstein at nextsilicon.com
                CC: llvm-bugs at lists.llvm.org

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200612/0e083084/attachment.html>


More information about the llvm-bugs mailing list