diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index 14179afcaeb8..1f4313dd296f 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -902,6 +902,9 @@ void ObjFile::registerCompactUnwind() { referentIsec = cast(r.referent.dyn_cast()); } + if (referentIsec->getSegName() != segment_names::text) + error("compact unwind references address in " + toString(referentIsec) + + " which is not in segment __TEXT"); // The functionAddress relocations are typically section relocations. // However, unwind info operates on a per-symbol basis, so we search for // the function symbol here. diff --git a/lld/test/MachO/invalid/compact-unwind-bad-reloc.s b/lld/test/MachO/invalid/compact-unwind-bad-reloc.s index 9204cafcfc81..3e189dada0ca 100644 --- a/lld/test/MachO/invalid/compact-unwind-bad-reloc.s +++ b/lld/test/MachO/invalid/compact-unwind-bad-reloc.s @@ -1,13 +1,12 @@ # REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %s -o %t.o -# RUN: not %lld -pie -lSystem -lc++ %t.o -o %t 2>&1 | FileCheck %s -DFILE=%t.o +# RUN: rm -rf %t; split-file %s %t +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/bad-function.s -o %t/bad-function.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %t/bad-personality.s -o %t/bad-personality.o +# RUN: not %lld -pie -lSystem -lc++ %t/bad-function.o -o %t 2>&1 | FileCheck %s -DFILE=%t/bad-function.o +# RUN: not %lld -pie -lSystem -lc++ %t/bad-personality.o -o %t 2>&1 | FileCheck %s -DFILE=%t/bad-personality.o # CHECK: error: compact unwind references address in [[FILE]]:(__data) which is not in segment __TEXT -.globl _main, _not_a_function -.text -_main: - retq - +#--- bad-function.s .data _not_a_function: .cfi_startproc @@ -15,3 +14,17 @@ _not_a_function: .cfi_def_cfa_offset 16 retq .cfi_endproc + +#--- bad-personality.s +.globl _main, _not_a_function +.text +_main: + .cfi_startproc + .cfi_personality 155, _my_personality + .cfi_def_cfa_offset 16 + retq + .cfi_endproc + +.data +.globl _my_personality +_my_personality: