[llvm-dev] Linux/ARM: Segfault issue when we build clang sources including __thread variable using -O2 flag

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Wed May 11 11:58:38 PDT 2016


On 11 May 2016 at 08:14, Geunsik Lim <leemgs at gmail.com> wrote:
> At first glance, it seems that the key difference is "bl _ZNK7TypeKey10GetNumArgsEv(PLT)"
> between -O1 and -O2 from the clsload.s file.

You're looking at the wrong compilation of clsload.c. If you look at
the log file it gets compiled 3 times, I think it's the 3rd time that
things go wrong.

Beyond that, you can't just match up constpool entries like that. The
numbering can change for all sorts of reasons at different
optimization levels and those two snippets of code look completely
unrelated to me.

> Could you tell me one example to understand what it is problem?

The commit had a test-case (also attached here). If you compile that
with "llc -mtriple=thumbv7-linux-gnueabihf -relocation-model=pic
simple.ll -o -" you should see something like this on a bad compiler:

        ldr r5, .LCPI0_0
        mov r6, r5
    .LPC0_1:
        add r5, pc
    .LPC0_0:
        add r6, pc
        [...]
        mov r0, r6
        bl __tls_get_addr(PLT)
        [...]
        mov r0, r5
        bl __tls_get_addr(PLT)
        [...]
    .LCPI0_0:
    .Ltmp0:
        .long var(TLSGD)-((.LPC0_0+4)-.Ltmp0)

The key point is that r0 should be the same before each call to
__tls_get_addr (it's a pointer to var's GOT entry) but that's
impossible because r5 gets added to two different values of PC (the
program counter).

Cheers.

Tim.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simple.ll
Type: application/octet-stream
Size: 983 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160511/3081c366/attachment.obj>


More information about the llvm-commits mailing list