| Issue |
233906
|
| Summary |
ld64.lld silently mis-links programs with a chained fixup that straddles a page boundary
|
| Labels |
|
| Assignees |
|
| Reporter |
nico
|
```
% cat lld-macho-bigdata/straddle.c
struct __attribute__((packed, aligned(16384))) S {
char pad[0x7ffc];
int (*q)(void);
};
static int done(void) { return 42; }
struct S s = {{0}, done};
int main(void) { return s.q(); }
```
`s.q` is a 4-byte-aligned pointer that sits at offset 0x3ffc of a 16 KiB page, so its 8 bytes cross a page boundary.
```
% bin/clang lld-macho-bigdata/straddle.c -isysroot $(xcrun -show-sdk-path) -fuse-ld=lld
% ./a.out
zsh: segmentation fault ./a.out
```
Xcode's ld diagnoses this. On arm64::
```
% bin/clang lld-macho-bigdata/straddle.c -isysroot $(xcrun -show-sdk-path)
ld: pointer not aligned in '_s'+0x7FFC (straddle-08b01b.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
On x86_64 it's just a warning:
```
% bin/clang --target=x86_64-apple-macos lld-macho-bigdata/straddle.c -isysroot $(xcrun -show-sdk-path)
ld: warning: reducing alignment of section __DATA,__data from 0x4000 to 0x1000 because it exceeds segment maximum alignment
ld: warning: disabling chained fixups because of unaligned pointers
ld: warning: pointer not aligned in '_s'+0x7FFC (straddle-13a3b1.o)
```
We should probably just always reject this. (Cases that linked without diag before and with diag when we add the diag had a silent latent mis-link embedded, which seems worse than a diag.)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs