Skip to content

[iA] LOCAL label .altmacro syntax unsupported #44396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nickdesaulniers opened this issue Feb 27, 2020 · 6 comments
Open

[iA] LOCAL label .altmacro syntax unsupported #44396

nickdesaulniers opened this issue Feb 27, 2020 · 6 comments
Assignees
Labels
backend:X86 bugzilla Issues migrated from bugzilla

Comments

@nickdesaulniers
Copy link
Member

Bugzilla Link 45051
Version unspecified
OS Linux
Blocks #4440
CC @jcai19,@echristo,@MaskRay,@isanbard,@zygoloid,@lenary,@stephenhines

Extended Description

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

@nickdesaulniers
Copy link
Member Author

assigned to @jcai19

@lenary
Copy link
Member

lenary commented Jul 9, 2020

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

@jcai19
Copy link
Member

jcai19 commented Jun 25, 2021

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

@jcai19
Copy link
Member

jcai19 commented Jul 9, 2021

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

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@paulmenzel
Copy link

Is issue #48543 a duplicate of this here?

@ostannard ostannard marked this as a duplicate of #48543 Apr 18, 2025
@EugeneZelenko EugeneZelenko added backend:X86 and removed clang Clang issues not falling into any other category labels Apr 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 18, 2025

@llvm/issue-subscribers-backend-x86

Author: Nick Desaulniers (nickdesaulniers)

| | | | --- | --- | | Bugzilla Link | [45051](https://llvm.org/bz45051) | | Version | unspecified | | OS | Linux | | Blocks | llvm/llvm-project#4440 | | CC | @jcai19,@echristo,@MaskRay,@isanbard,@zygoloid,@lenary,@stephenhines |

Extended Description

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

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

foo

<instantiation>: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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

6 participants