Skip to content

[lld] Discard SHT_LLVM_LTO sections in relocatable links #92825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
17 changes: 4 additions & 13 deletions lld/test/ELF/fatlto/fatlto.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
; RUN: opt < a-LTO.ll --module-summary -o a-fatLTO.bc
; RUN: llvm-objcopy --add-section=.llvm.lto=a-fatLTO.bc --set-section-flags=.llvm.lto=exclude --set-section-type=.llvm.lto=0x6fff4c0c a-fatLTO.o


; RUN: llc main-LTO.ll --filetype=obj -o main-fatLTO.o --relocation-model=pic
; RUN: opt < main-LTO.ll --module-summary -o main-fatLTO.bc
; RUN: llvm-objcopy --add-section=.llvm.lto=main-fatLTO.bc --set-section-flags=.llvm.lto=exclude --set-section-type=.llvm.lto=0x6fff4c0c main-fatLTO.o
Expand All @@ -17,11 +16,6 @@
; RUN: llvm-readelf -S main-fatLTO.o | FileCheck --check-prefix=HAS_LLVM_LTO %s

;; Make sure that the section flags are set correctly
; HA_LLVM_LTO: Name: .llvm.lto
; HA_LLVM_LTO-NEXT: Type: SHT_LLVM_LTO
; HA_LLVM_LTO-NEXT: Flags
; HA_LLVM_LTO-NEXT: SHF_EXCLUDE

; HAS_LLVM_LTO: Name Type Address Off Size ES Flg Lk Inf Al
; HAS_LLVM_LTO: .llvm.lto LLVM_LTO {{.*}} 00 WE 0 0 1

Expand Down Expand Up @@ -64,16 +58,13 @@
; RUN: ld.lld -o foo-fatLTO.archive a.a main-LTO.bc --fat-lto-objects
; RUN: cmp foo-fatLTO.archive foo-LTO

;; Test FatLTO works with relocatable links using PIC objects
;; Currently, with PIC relocatable links, FatLTO sections are treated as
;; orphan sections and incorrectly concatenated together. This test verifies
;; the current behavior, but should be fixed to either merge those sections
;; correctly, or to drop them altogether.
;; Test FatLTO works with relocatable links using PIC objects, and that
;; SHT_LLVM_LTO sections are discarded.
; RUN: llvm-ar rcs fatLTO-pic.a a-fatLTO.o main-fatLTO.o
; RUN: llvm-readelf -S fatLTO-pic.a | FileCheck --check-prefix=HAS_LLVM_LTO %s

; RUN: ld.lld --whole-archive fatLTO-pic.a -r -o fatLTO-pic-reolcatable.o
; RUN: llvm-readelf -S fatLTO-pic-reolcatable.o | FileCheck --check-prefix=HAS_LLVM_LTO %s
; RUN: ld.lld --whole-archive fatLTO-pic.a -r -o fatLTO-pic-relocatable.o
; RUN: llvm-readelf -S fatLTO-pic-relocatable.o | FileCheck --check-prefix=CHECK-NON-LTO-TARGET %s

;--- a-LTO.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
Expand Down
Loading