llvm / llvm/llvm-project

[libc] non-local conditional branch (cbz) in aarch64/sigsetjmp.cpp

Open
#164,939 1 comment 0 reactions 0 assignees View on GitHub
libc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

sigsetjmp.cpp in [aarch64/sigsetjmp.cpp](https://github.com/llvm/llvm-project/blob/a1e59bdc173187ec47e6ede69c99316eaee9e375/libc/src/setjmp/aarch64/sigsetjmp.cpp#L20) uses a non-local label (that of setjmp) in the cbz instruction. Compiling this on aarch64 (MacOS) leads to an error:

```
error: conditional branch requires assembler-local label. '__ZN22__llvm_libc_22_0_0_git6setjmpEP9__jmp_buf' is external.
20 | cbz w1, %c[setjmp]
| ^
:2:7: note: instantiated into assembly here
2 | cbz w1, __ZN22__llvm_libc_22_0_0_git6setjmpEP9__jmp_buf
```

Here's a minimal reproducible example:
```
void external_target(void) {}

void foo(int condition) {
asm volatile(
// ERROR: cbz requires a local label (e.g., .Lskip_target), not an
// external symbol.
"cbz w0, %c[target] \n"
"nop \n"
:
: [target] "i"(external_target)
: "w0"
);
}

int main() {
foo(0);
return 0;
}
```
Compile this with clang -target aarch64 example.c -o a

@michaelrj-google

Contributor guide

Open the contributing guide

Research direction

Start with libc/src/setjmp/aarch64/sigsetjmp.cpp at the inline assembly around line 20, then reproduce the reported failure with the provided aarch64 clang command. Determine how the conditional branch can assemble on AArch64 when targeting setjmp, and verify that the file compiles successfully without the assembler error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.