[llvm-bugs] [Bug 27688] New: clang reorders module level asm statements
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon May 9 12:36:49 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=27688
Bug ID: 27688
Summary: clang reorders module level asm statements
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: rjones at redhat.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 16335
--> https://llvm.org/bugs/attachment.cgi?id=16335&action=edit
asmorder.c
Firstly, I realize here that I'm operating well outside any C standards or
guarantees of any sort. But this stuff is useful for some people.
If you want to write a PC BIOS option ROM in C, you can do it in
gcc using asm statements at the module level of the C file, at the
start and end. These asm statements contain the option ROM header
and trailing and effectively "bracket" the C code in the middle.
(See attached example).
This can be compiled using:
gcc -m16 -c asmorder.c
ld -m elf_i386 -Ttext 0 -e _start -s -o asmorder.img asmorder.o
objcopy -O binary -j .text asmorder.img asmorder.bin
to produce the option ROM (I missed out a step for computing the
checksum of the ROM but it's not relevant for this discussion).
If you disassemble the object file, you'll see that the order of
the start & end asm statements is preserved, and the size of the
file in the header is computed correctly:
objdump -d asmorder.o
However this does not work if you substitute clang for gcc.
The problem is that clang reorders the module level asm statements,
putting them all at the start of the file, and so the option ROM
format isn't recognized.
In short, gcc converts:
asm("some stuff");
some_C_functions;
asm("more stuff");
into:
some stuff
assembler of some_C_functions
more stuff
but clang turns it into:
some stuff
more stuff
assembler of some_C_functions
Note I'm not using any optimization.
It would be nice if clang didn't do that, at least for asm statements
appearing at the beginning and end of the file.
gcc-6.0.0-0.20.fc24.x86_64 (also works in gcc 4 & 5)
clang-3.8.0-1.fc24.x86_64
--
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/20160509/b27a4e8b/attachment.html>
More information about the llvm-bugs
mailing list