This is an archive of the discontinued LLVM Phabricator instance.

Add missing nullptr check before getSection() to AArch64MachObjectWriter::recordRelocation
ClosedPublic

Authored by paquette on Apr 9 2018, 3:16 PM.

Details

Summary

There was a missing nullptr check in AArch64MachObjectWriter::recordRelocation which would cause a segfault in code like the attached test.

This patch adds the missing check and ensures that we get an error message instead of a crash.

Diff Detail

Event Timeline

paquette created this revision.Apr 9 2018, 3:16 PM
This revision is now accepted and ready to land.Apr 10 2018, 6:38 AM
paquette closed this revision.Apr 10 2018, 8:57 AM

Committed in r329716.

FYI – This test fails on my machine (Release+Assert):

FAIL: LLVM :: MC/AArch64/arm64-no-section.ll (28812 of 38754)
******************** TEST 'LLVM :: MC/AArch64/arm64-no-section.ll' FAILED ********************
Script:
--
/tmp/_update_lc_t/bin/llc -mtriple=aarch64-darwin-- -filetype=obj /home/dave/s/lc/test/MC/AArch64/arm64-no-section.ll -o -
--
Exit Code: 134

Command Output (stderr):
--
This constant variable should have been expanded during evaluation
UNREACHABLE executed at /home/dave/s/lc/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp:358!
#0 0x0000000002033b7f llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/tmp/_update_lc_t/bin/llc+0x2033b7f)
#1 0x0000000002033e86 SignalHandler(int) (/tmp/_update_lc_t/bin/llc+0x2033e86)
#2 0x00007ff9049d0fb0 __restore_rt (/lib64/libpthread.so.0+0x11fb0)
#3 0x00007ff903346f4b __GI_raise (/lib64/libc.so.6+0x36f4b)
#4 0x00007ff903331591 __GI_abort (/lib64/libc.so.6+0x21591)
#5 0x0000000001fde378 (/tmp/_update_lc_t/bin/llc+0x1fde378)
#6 0x00000000013869aa (anonymous namespace)::AArch64MachObjectWriter::recordRelocation(llvm::MachObjectWriter*, llvm::MCAssembler&, llvm::MCAsmLayout const&, llvm::MCFragment const*, llvm::MCFixup const&, llvm::MCValue, unsigned long&) (/tmp/_update_lc_t/bin/llc+0x13869aa)
#7 0x0000000001b23223 llvm::MachObjectWriter::recordRelocation(llvm::MCAssembler&, llvm::MCAsmLayout const&, llvm::MCFragment const*, llvm::MCFixup const&, llvm::MCValue, unsigned long&) (/tmp/_update_lc_t/bin/llc+0x1b23223)
#8 0x0000000001aed865 llvm::MCAssembler::layout(llvm::MCAsmLayout&) (/tmp/_update_lc_t/bin/llc+0x1aed865)
#9 0x0000000001aedb4b llvm::MCAssembler::Finish() (/tmp/_update_lc_t/bin/llc+0x1aedb4b)
#10 0x0000000001b0cd2f (anonymous namespace)::MCMachOStreamer::FinishImpl() (/tmp/_update_lc_t/bin/llc+0x1b0cd2f)
#11 0x00000000015c8394 llvm::AsmPrinter::doFinalization(llvm::Module&) (/tmp/_update_lc_t/bin/llc+0x15c8394)
#12 0x0000000001a7086f llvm::FPPassManager::doFinalization(llvm::Module&) (/tmp/_update_lc_t/bin/llc+0x1a7086f)
#13 0x0000000001a70de0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/tmp/_update_lc_t/bin/llc+0x1a70de0)
#14 0x0000000000ff99d7 compileModule(char**, llvm::LLVMContext&) (/tmp/_update_lc_t/bin/llc+0xff99d7)
#15 0x0000000000ff70bb main (/tmp/_update_lc_t/bin/llc+0xff70bb)
#16 0x00007ff9033331bb __libc_start_main (/lib64/libc.so.6+0x231bb)
#17 0x0000000000ff602a _start (/tmp/_update_lc_t/bin/llc+0xff602a)
Stack dump:
0.      Program arguments: /tmp/_update_lc_t/bin/llc -mtriple=aarch64-darwin-- -filetype=obj /home/dave/s/lc/test/MC/AArch64/arm64-no-section.ll -o - 
/tmp/_update_lc_t/test/MC/AArch64/Output/arm64-no-section.ll.script: line 1: 274231 Aborted                 /tmp/_update_lc_t/bin/llc -mtriple=aarch64-darwin-- -filetype=obj /home/dave/s/lc/test/MC/AArch64/arm64-no-section.ll -o -

--

Currently looking into it.

I think I can have a fix up in a few minutes. If not I’ll revert.

  • Jessica

I think (hope) r329723 should fix it…

  • Jessica