mirror of
https://github.com/intel/llvm.git
synced 2026-02-06 15:18:53 +08:00
[lld] Discard SHT_LLVM_LTO sections in relocatable links (#92825)
So long as ld -r links using bitcode always result in an ELF object, and not a merged bitcode object, the output form a relocatable link using FatLTO objects should not have a .llvm.lto section. Prior to this, using the object code sections would cause the bitcode section in the output of a relocatable link to be corrupted, by concatenating all the .llvm.lto sections together. This patch discards SHT_LLVM_LTO sections when not using --fat-lto-objects, so that the relocatable ELF output won't contain inalid bitcode.
This commit is contained in:
@@ -844,6 +844,16 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
|
||||
this->sections[i] =
|
||||
createInputSection(i, sec, check(obj.getSectionName(sec, shstrtab)));
|
||||
break;
|
||||
case SHT_LLVM_LTO:
|
||||
// Discard .llvm.lto in a relocatable link that does not use the bitcode.
|
||||
// The concatenated output does not properly reflect the linking
|
||||
// semantics. In addition, since we do not use the bitcode wrapper format,
|
||||
// the concatenated raw bitcode would be invalid.
|
||||
if (config->relocatable && !config->fatLTOObjects) {
|
||||
sections[i] = &InputSection::discarded;
|
||||
break;
|
||||
}
|
||||
[[fallthrough]];
|
||||
default:
|
||||
this->sections[i] =
|
||||
createInputSection(i, sec, check(obj.getSectionName(sec, shstrtab)));
|
||||
|
||||
Reference in New Issue
Block a user