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
llvm-tblgen fails to run during a release build with lld as host linker on arm macs #48788
Comments
(lldb) bt
|
What's basically going wrong here is that ConcatStringInits() in lib/TableGen/Record.cpp creates a SmallString<80> on the stack and passes it to append() (the SmallString<> ctor gets optimized to an append() call). But in append, the code thinks that the SmallVector (which backs SmallString) has a size of 7953764196914526053 instead of 0, and then things go wrong. objdump -dr of the relevant bits of Record.o (I added an attribute((noinline)) to ConcatStringInits()), with lots of notes since I'm fairly new to arm64 asm: in-memory layout of SmallVector, all words 64 bit: 0000000000004cb0 _ZL17ConcatStringInitsPKN4llvm10StringInitES2:
^ copy parameters to temp regs
^ stack guard setup actually interesting code below
this here then inits size and capacity via a constant island as far as I understand. That's what goes wrong: and then we call append with x0, x1, x2: The size/cap init lines after linking with ld64:
Same after linking with lld:
ld64 does a relaxation optimization (not just here, but in many places), but that in itself isn't the cause. The piecewise_construct in ld64's output looks like just a coincidence. I don't know how to dump the constant island data yet. Maybe the wrong data is stored there (do constant islands have relocations?), or alignment to it is wrong or what. There are tons of ARM64_RELOC_PAGE21 / ARM64_RELOC_PAGEOFF12 relocs in the output so lld likely doesn't get those relocs completely wrong. |
I haven't confirmed this yet, but I was looking at a different crash today that makes me believe that our |
If I run 00000000000187b8 lCPI82_0: 00000000000187c0 lCPI87_0: But no lCPI86_0. ..aha!: thakis@M1BP gn % nm ./obj/llvm/lib/TableGen/TableGen.Record.o | grep lCPI86_0 So ltmp3 and lCPI86_0 are the same address. (Is there some way to tell objdump to not symbolize reloc destinations?) Slightly easier to see with dsymutil which sorts by address instead of symbol name: thakis@M1BP gn % dsymutil -s ./obj/llvm/lib/TableGen/TableGen.Record.o | grep -C1 lCPI86_0 and there's an ltmp3: 0000000000018920 : That's 80 for the capacity of the SmallString<80> and 0 for the size. (Swapped because little endian and use of stur to store it to the stack.) So the relocation to that data island is somehow not done correctly by lld. |
If I read the code right, we already do what you think we should do. I think what's going wrong is that encodePageOff12 doesn't check for vector ops when computing scale. This seems to fix it: -inline uint64_t encodePageOff12(uint64_t base, uint64_t va) {
I'll read some more and do some more testing, then I'll add tests and send it out. |
Extended Description
thakis@M1BP llvm-project % time caffeinate ninja -C out/gn lld
ninja: Entering directory `out/gn'
[11/1390] ACTION //lld/wasm:Options(//llvm/utils/gn/build/toolchain:unix)
FAILED: gen/lld/wasm/Options.inc
python3 ../../llvm/utils/gn/build/run_tablegen.py bin/llvm-tblgen --write-if-changed -I ../../llvm/include -I ../../lld/wasm -d gen/lld/wasm/Options.inc.d -o gen/lld/wasm/Options.inc ../../lld/wasm/Options.td -gen-opt-parser-defs
LLVM ERROR: out of memory
Allocation failed
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
LLVM ERROR: out of memory
Allocation failed
Doesn't happen in a debug build.
The text was updated successfully, but these errors were encountered: