-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
-fasm-blocks: __asm { call fptr } does not use RIP-relative addressing #73033
Comments
@llvm/issue-subscribers-clang-codegen Author: David Miller (dmiller423)
``
clang version 17.0.4
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\dev\llvm\bin``
Target is a simple static library, contents: two functions one __weak_symbol attribute((naked)) containing assembly in intel format that calls a static global address in the same file (set by the second function). The generated objects are not position independent code, using R_X86_64_32S for relocations of the functions containing asm blocks declared as weak. tested TARGET list -- objects relocations were tested via readelf and custom tooling, all cases produce:
rebuilding the same file/params with a previous version (clang-15.0.7):
source: #include <stdint.h>
#include <sys/types.h>
static uint64_t syscall_addr = 0;
int syscalls_init(uint64_t addr) {
syscall_addr = addr;
return 0;
}
__weak_symbol
__attribute__((naked))
ssize_t read(int fd, void* buf, size_t nbytes) {
__asm {
push rbp
mov rbp, rsp
mov eax, 3
mov r10, rcx
call syscall_addr
pop rbp
ret
}
} |
Related to https://reviews.llvm.org/D151863? CC @MaskRay @KanRobert @akshaykhadse |
Adding back |
https://reviews.llvm.org/D151863 (2023-05) removed `BaseReg = BaseReg ? BaseReg : 1` (introduced in commit 175d0ae (2013)) and caused a regression: ensuring a non-zero `BaseReg` was to treat `static void (*fptr)(); __asm { call fptr }` as non-`AbsMem` `AsmOperandClass` and generate `call $0`/`callq *fptr(%rip)` instead of `call ${0:P}`/`callq *fptr` (The asm template argument modifier `P` is for call targets, while no modifier is used by other instructions like `mov rax, fptr`) This patch reinstates the BaseReg-setting statement but places it inside `if (IsGlobalLV)` for clarify. The special case is unfortunate, but we also have special case in similar places (https://reviews.llvm.org/D149920). Fix: llvm#73033
https://reviews.llvm.org/D151863 (2023-05) removed `BaseReg = BaseReg ? BaseReg : 1` (introduced in commit 175d0ae (2013)) and caused a regression: ensuring a non-zero `BaseReg` was to treat `static void (*fptr)(); __asm { call fptr }` as non-`AbsMem` `AsmOperandClass` and generate `call $0`/`callq *fptr(%rip)` instead of `call ${0:P}`/`callq *fptr` (The asm template argument modifier `P` is for call targets, while no modifier is used by other instructions like `mov rax, fptr`) This patch reinstates the BaseReg-setting statement but places it inside `if (IsGlobalLV)` for clarify. The special case is unfortunate, but we also have special case in similar places (https://reviews.llvm.org/D149920). Fix: #73033
@llvm/issue-subscribers-backend-x86 Author: David Miller (dmiller423)
``
clang version 17.0.4
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\dev\llvm\bin``
Target is a simple static library, contents: two functions one __weak_symbol attribute((naked)) containing assembly in intel format that calls a static global address in the same file (set by the second function). The generated objects are not position independent code, using R_X86_64_32S for relocations of the functions containing asm blocks declared as weak. tested TARGET list -- objects relocations were tested via readelf and custom tooling, all cases produce:
rebuilding the same file/params with a previous version (clang-15.0.7):
source: #include <stdint.h>
#include <sys/types.h>
static uint64_t syscall_addr = 0;
int syscalls_init(uint64_t addr) {
syscall_addr = addr;
return 0;
}
__weak_symbol
__attribute__((naked))
ssize_t read(int fd, void* buf, size_t nbytes) {
__asm {
push rbp
mov rbp, rsp
mov eax, 3
mov r10, rcx
call syscall_addr
pop rbp
ret
}
} |
clang version 17.0.4 Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\dev\llvm\bin
Target is a simple static library, contents: two functions one __weak_symbol attribute((naked)) containing assembly in intel format that calls a static global address in the same file (set by the second function).
The generated objects are not position independent code, using R_X86_64_32S for relocations of the functions containing asm blocks declared as weak.
tested TARGET list
{ x86_64-pc-freebsd12-elf, x86_64-pc-unknown-elf, x86_64-pc-linux-gnu }
--
reproduction:
clang-17.0.4 --target=%TARGET% --sysroot=C:/tc_sysroot/%TARGET%/ -fPIC -fPIE -fasm-blocks -MD -MT syscalls.c.o -MF syscalls.c.o.d -o syscalls.c.o -c syscalls.c
objects relocations were tested via readelf and custom tooling, all cases produce:
> readelf -r syscalls.c.o
rebuilding the same file/params with a previous version (clang-15.0.7):
> readelf -r syscalls.c.o
source:
The text was updated successfully, but these errors were encountered: