[LLVMbugs] [Bug 9297] New: Bad movaps code emitted when string arrays exist in function scope, in binary linkage

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Feb 23 08:56:17 PST 2011


http://llvm.org/bugs/show_bug.cgi?id=9297

           Summary: Bad movaps code emitted when string arrays exist in
                    function scope, in binary linkage
           Product: clang
           Version: 2.8
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: morgon.kanter at gmail.com
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=6215)
 --> (http://llvm.org/bugs/attachment.cgi?id=6215)
Test case for bad code

clang is emitting code that works when linked as an ELF file, but does not work
when linked as a flat binary file. When an array of strings is placed in
function scope, it emits several "movaps" instructions -- even if this string
array is never referenced (see test case). When this array of strings is
removed, no movaps instructions are emitted.

This works fine when linking as an ELF file (ld -e main -o test_bad test_bad.o
-lc) -- everything is 16-byte aligned correctly for movaps. However, when
linked as a binary file (ld -e main --target=binary -o test_bad test_bad.o)*,
the emitted code is completely wrong:

 110:   0f 28 05 00 00 00 00    movaps 0x0(%rip),%xmm0        # 0x117
 117:   0f 29 41 20             movaps %xmm0,0x20(%rcx)
 11b:   0f 28 05 00 00 00 00    movaps 0x0(%rip),%xmm0        # 0x122
 122:   0f 29 41 10             movaps %xmm0,0x10(%rcx)
 126:   0f 28 05 00 00 00 00    movaps 0x0(%rip),%xmm0        # 0x12d
 12d:   0f 29 01                movaps %xmm0,(%rcx)

It's not touching the strings at this point, and the addressing for movaps is
not 16-byte aligned.

This may be a linker bug and not a clang bug. I'm not sure whose job it is to
do "the right thing".

* I know this code won't actually run even in the "correct" case, as it's not
linked with the appropriate start-up stuff. This was just meant to be
demonstrative of the issue -- it's appearing in a flat binary file part of a
larger project that does run. I'm not sure what commands to issue the linker to
add the _start function and other requirements to get an ELF file to run on
Linux.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list