Skip to content
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

wasm32 assertion failure in writePatchableLEB() #54012

Closed
nikic opened this issue Feb 23, 2022 · 12 comments
Closed

wasm32 assertion failure in writePatchableLEB() #54012

nikic opened this issue Feb 23, 2022 · 12 comments

Comments

@nikic
Copy link
Contributor

nikic commented Feb 23, 2022

target triple = "wasm32-unknown-unknown"

@c = private constant i8* null

define i8* @test() {
  %v = load i8*, i8** getelementptr (i8*, i8** @c, i32 -1), align 4
  ret i8* %v
}

With llc -filetype=obj, this results in an assertion failure:

llc: /home/npopov/repos/llvm-project/llvm/lib/MC/WasmObjectWriter.cpp:146: void {anonymous}::writePatchableLEB(llvm::raw_pwrite_stream&, uint64_t, uint64_t) [with int W = 5; uint64_t = long unsigned int]: Assertion `SizeLen == W' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: build/bin/llc -filetype=obj
[...]
 #8 0x00000000028392cb (anonymous namespace)::WasmObjectWriter::applyRelocations(llvm::ArrayRef<(anonymous namespace)::WasmRelocationEntry>, unsigned long, llvm::MCAsmLayout const&) WasmObjectWriter.cpp:0:0
 #9 0x000000000283e87e (anonymous namespace)::WasmObjectWriter::writeOneObject(llvm::MCAssembler&, llvm::MCAsmLayout const&, (anonymous namespace)::WasmObjectWriter::DwoMode) WasmObjectWriter.cpp:0:0
#10 0x000000000283f1d7 (anonymous namespace)::WasmObjectWriter::writeObject(llvm::MCAssembler&, llvm::MCAsmLayout const&) WasmObjectWriter.cpp:0:0
#11 0x00000000027ba976 llvm::MCAssembler::Finish() (build/bin/llc+0x27ba976)
#12 0x0000000001fb88fb llvm::AsmPrinter::doFinalization(llvm::Module&) (build/bin/llc+0x1fb88fb)
#13 0x00000000026f4ddd llvm::FPPassManager::doFinalization(llvm::Module&) (build/bin/llc+0x26f4ddd)
#14 0x000000000270099f llvm::legacy::PassManagerImpl::run(llvm::Module&) (build/bin/llc+0x270099f)
#15 0x0000000000674f88 main (build/bin/llc+0x674f88)

Of course, the input IR is UB, but it probably shouldn't crash?

@llvmbot
Copy link
Member

llvmbot commented Feb 23, 2022

@llvm/issue-subscribers-backend-webassembly

@sbc100 sbc100 self-assigned this Feb 23, 2022
@sbc100
Copy link
Collaborator

sbc100 commented Feb 24, 2022

Proposed fix is here: https://reviews.llvm.org/D120522

@sbc100 sbc100 closed this as completed in 4c75521 Feb 25, 2022
@nikic
Copy link
Contributor Author

nikic commented Feb 25, 2022

/cherry-pick 4c75521

@nikic nikic reopened this Feb 25, 2022
@nikic nikic added this to the LLVM 14.0.0 Release milestone Feb 25, 2022
@llvmbot
Copy link
Member

llvmbot commented Feb 25, 2022

Failed to cherry-pick: 4c75521

https://github.com/llvm/llvm-project/actions/runs/1899393567

Please manually backport the fix and push it to your github fork. Once this is done, please add a comment like this:

/branch <user>/<repo>/<branch>

@sbc100
Copy link
Collaborator

sbc100 commented Feb 25, 2022

@nikic are you able to take care of that cherry pick?

@nikic
Copy link
Contributor Author

nikic commented Feb 25, 2022

I think this is just missing a dependent revision that modified the test...

/cherry-pick db7b1af 4c75521

@llvmbot
Copy link
Member

llvmbot commented Feb 25, 2022

/branch llvmbot/llvm-project/issue54012

llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Feb 25, 2022
For the object file writer we need to allow the underflow (ar write
zero), but for the final linker output we should probably generate an
error (I've left that as a TODO for now).

Fixes: llvm#54012

Differential Revision: https://reviews.llvm.org/D120522

(cherry picked from commit 4c75521)
@llvmbot
Copy link
Member

llvmbot commented Feb 25, 2022

/pull-request llvmbot#103

@tstellar
Copy link
Collaborator

tstellar commented Mar 1, 2022

@sunfishcode What do you think about backporting these? db7b1af 4c75521

@nikic
Copy link
Contributor Author

nikic commented Mar 7, 2022

I don't think that @sunfishcode is still active in LLVM, it would probably be good if one of the current WebAssembly maintainers (@aheejin @tlively @pmatos @sbc100 maybe?) could pick a new code owner and add them in

N: Dan Gohman
E: llvm@sunfishcode.online
D: WebAssembly Backend (lib/Target/WebAssembly/*)
.

@sunfishcode
Copy link
Member

@tstellar Yes, backporting both those patches looks good to me.

tstellar pushed a commit to llvmbot/llvm-project that referenced this issue Mar 7, 2022
For the object file writer we need to allow the underflow (ar write
zero), but for the final linker output we should probably generate an
error (I've left that as a TODO for now).

Fixes: llvm#54012

Differential Revision: https://reviews.llvm.org/D120522

(cherry picked from commit 4c75521)
@tstellar
Copy link
Collaborator

tstellar commented Mar 7, 2022

Merged: f6a4df3 e6d2aa9

mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
For the object file writer we need to allow the underflow (ar write
zero), but for the final linker output we should probably generate an
error (I've left that as a TODO for now).

Fixes: llvm/llvm-project#54012

Differential Revision: https://reviews.llvm.org/D120522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants