Index: lld/MachO/SyntheticSections.cpp =================================================================== --- lld/MachO/SyntheticSections.cpp +++ lld/MachO/SyntheticSections.cpp @@ -933,8 +933,8 @@ if (entries.empty()) continue; - assert(is_sorted(dataInCodeEntries, [](const data_in_code_entry &lhs, - const data_in_code_entry &rhs) { + assert(is_sorted(entries, [](const data_in_code_entry &lhs, + const data_in_code_entry &rhs) { return lhs.offset < rhs.offset; })); // For each code subsection find 'data in code' entries residing in it. Index: lld/test/MachO/data-in-code-section-ordering.s =================================================================== --- /dev/null +++ lld/test/MachO/data-in-code-section-ordering.s @@ -0,0 +1,32 @@ +# REQUIRES: x86 +# RUN: rm -rf %t; split-file %s %t + +## Check that data-in-code info is emitted correctly even if sections are reordered +## compared to the input order. This test case used to trigger an incorrect assertion. + +# RUN: sed -e s/SYM/_first/ %t/input.s | \ +# RUN: llvm-mc -filetype=obj --triple=x86_64-apple-darwin -o %t/first.o +# RUN: sed -e s/SYM/_second/ %t/input.s | \ +# RUN: llvm-mc -filetype=obj --triple=x86_64-apple-darwin -o %t/second.o +# RUN: sed -e s/SYM/_third/ %t/input.s | \ +# RUN: llvm-mc -filetype=obj --triple=x86_64-apple-darwin -o %t/third.o +# RUN: %lld -dylib -lSystem -order_file %t/order.txt %t/first.o %t/second.o %t/third.o -o %t/out +# RUN: llvm-objdump --macho --data-in-code %t/out | FileCheck %s + +# CHECK: Data in code table (3 entries) +# CHECK: offset length kind +# CHECK: 0x{{[0-9a-z]+}} 4 JUMP_TABLE32 +# CHECK: 0x{{[0-9a-z]+}} 4 JUMP_TABLE32 +# CHECK: 0x{{[0-9a-z]+}} 4 JUMP_TABLE32 + +#--- order.txt +_second +_first +_third + +#--- input.s +.globl SYM +SYM: +.data_region jt32 +.long 0 +.end_data_region