Page MenuHomePhabricator

LTO C API: always parse modules in opaque pointer mode.

Authored by t.p.northover on Dec 13 2022, 2:22 AM.



Once an LLVMContext has been told it needs to track pointer types, it can no longer be used to parse opaque modules. However, we are likely (at least for a while) to have old LTO .o files in the SDK that need to interoperate with just-generated ones, so deciding opaqueness based on the first module read causes linker failures.

This makes the llvm-c LTO interface (used by ld64) parse any object it sees in opaque mode, even if type data is present, which guarantees compatibility.

Diff Detail

Unit TestsFailed

60,180 msx64 debian > SanitizerCommon-Unit._/Sanitizer-x86_64-Test/36::48
Script(shard): -- GTEST_OUTPUT=json:/var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/lib/sanitizer_common/tests/./Sanitizer-x86_64-Test-SanitizerCommon-Unit-2202299-36-48.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=48 GTEST_SHARD_INDEX=36 /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/lib/sanitizer_common/tests/./Sanitizer-x86_64-Test
60,080 msx64 debian > SanitizerCommon-Unit._/Sanitizer-x86_64-Test/42::48
Script(shard): -- GTEST_OUTPUT=json:/var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/lib/sanitizer_common/tests/./Sanitizer-x86_64-Test-SanitizerCommon-Unit-2202299-42-48.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=48 GTEST_SHARD_INDEX=42 /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/lib/sanitizer_common/tests/./Sanitizer-x86_64-Test
60,040 msx64 debian > libFuzzer.libFuzzer::minimize_crash.test
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/./bin/clang --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/var/lib/buildkite-agent/builds/llvm-project/compiler-rt/lib/fuzzer -m64 /var/lib/buildkite-agent/builds/llvm-project/compiler-rt/test/fuzzer/NullDerefTest.cpp -o /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/test/fuzzer/X86_64DefaultLinuxConfig/Output/minimize_crash.test.tmp-NullDerefTest

Event Timeline

t.p.northover created this revision.Dec 13 2022, 2:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2022, 2:22 AM
t.p.northover requested review of this revision.Dec 13 2022, 2:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2022, 2:22 AM
This revision is now accepted and ready to land.Dec 13 2022, 6:08 AM
t.p.northover closed this revision.Dec 14 2022, 6:14 AM

Thanks, committed as 8ba9a5218782

dmgreen added inline comments.

Hi - We noticed from out downstream embedded linker that this can be null if it comes in via lto_codegen_create, as opposed to lto_codegen_create_in_local_context.

lenary added a subscriber: lenary.Dec 15 2022, 10:15 AM
lenary added inline comments.

We got downstream failures from this patch, because OwnedContext can be null here (if you use the first constructor on line 127, above).

I think maybe my suggestion is less falliable, but alters global state, so I'm not sure it's right either. It should at least work when OwnedContext is null, because the LTOCodeGenerator will still have a context to return (the global one)

nikic added a subscriber: nikic.Dec 15 2022, 10:38 AM

FWIW, now that D139940 has landed, you likely don't need this change at all.

w2yehia added inline comments.

this is breaking the AIX linker too - for the same reasons as above.

steven_wu added inline comments.Dec 19 2022, 4:03 PM

Reverted in 3a5426f57243.

It is likely this is not needed anymore.