Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

[iA] LOCAL label .altmacro syntax unsupported #44021

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR45051
Status NEW
Importance P enhancement
Reported by Nick Desaulniers (ndesaulniers@google.com)
Reported on 2020-02-27 15:02:11 -0800
Last modified on 2021-07-09 12:29:19 -0700
Version unspecified
Hardware PC Linux
CC caij2003@gmail.com, echristo@gmail.com, htmldeveloper@gmail.com, i@maskray.me, isanbard@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk, sam@lenary.co.uk, srhines@google.com
Fixed by commit(s)
Attachments
Blocks PR4068
Blocked by
See also

Buiding the RISC-V Linux kernel w/ Clang, we hit this error, ex:

.altmacro
.macro foo
LOCAL bar
bar:
jmp bar
.endm

foo
:1:1: error: invalid instruction mnemonic 'local' We can work around this via local labels, ie: ``` .macro foo 1: jmp 1b .endm foo ``` https://sourceware.org/binutils/docs/as/Macro.html#Macro documents `LOCAL`: Warning: LOCAL is only available if you select “alternate macro syntax” with ‘--alternate’ or .altmacro. See .altmacro. https://sourceware.org/binutils/docs/as/Altmacro.html#Altmacro
Quuxplusone commented 4 years ago

This looks like a general problem with LLVM's assembler support for LOCAL in .altmacro systems.

Quuxplusone commented 3 years ago
I can confirm this issue is target-independent. I wrote a small piece piece of
code to help myself understand the exact meaning of LOCAL. I'm putting it down
for future reference.

$ cat foo.s
.altmacro
.set x, 0

.macro write arg
.set x, \arg
mov x, %eax
.endm

.macro read
mov x, %ebx
.endm

write 16
read

$ as foo.s -o gas.o
$ objdump -d gas.o

gas.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <.text>:
   0:   8b 04 25 10 00 00 00    mov    0x10,%eax
   7:   8b 1c 25 10 00 00 00    mov    0x10,%ebx

Without LOCAL, the value of symbol "x" defined in the expansion of foo got read
in the macro expansion of bar. If I make "x" local in foo, then it's renamed
uniquely for each expansion of foo, and as a result bar would read its initial
value 0 instead.

$ cat foo.s
.altmacro
.set x, 0

.macro write arg
LOCAL x
.set x, \arg
mov x, %eax
.endm

.macro read
mov x, %ebx
.endm

write 16
read

$ as foo.s -o gas.o
$ objdump -d gas.o

gas.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <.text>:
   0:   8b 04 25 10 00 00 00    mov    0x10,%eax
   7:   8b 1c 25 00 00 00 00    mov    0x0,%ebx
Quuxplusone commented 3 years ago

Sent https://reviews.llvm.org/D105720 for review.