diff --git a/llvm/docs/Extensions.rst b/llvm/docs/Extensions.rst --- a/llvm/docs/Extensions.rst +++ b/llvm/docs/Extensions.rst @@ -463,6 +463,13 @@ for storing offloading metadata. This format is effectively a string table containing metadata accompanied by a device image. +``SHT_LLVM_LTO`` Section (LLVM bitcode for fat LTO) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +This section stores LLVM bitcode used to perform regular LTO or ThinLTO at link +time. This section is generated when the compiler enables fat LTO. This section +has the ``SHF_EXCLUDE`` flag so that it is stripped from the final executable +or shared library. + CodeView-Dependent ------------------ diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h --- a/llvm/include/llvm/BinaryFormat/ELF.h +++ b/llvm/include/llvm/BinaryFormat/ELF.h @@ -1036,6 +1036,7 @@ SHT_LLVM_CALL_GRAPH_PROFILE = 0x6fff4c09, // LLVM Call Graph Profile. SHT_LLVM_BB_ADDR_MAP = 0x6fff4c0a, // LLVM Basic Block Address Map. SHT_LLVM_OFFLOADING = 0x6fff4c0b, // LLVM device offloading data. + SHT_LLVM_LTO = 0x6fff4c0c, // .llvm.lto for fat LTO. // Android's experimental support for SHT_RELR sections. // https://android.googlesource.com/platform/bionic/+/b7feec74547f84559a1467aca02708ff61346d2a/libc/include/elf.h#512 SHT_ANDROID_RELR = 0x6fffff00, // Relocation entries; only offsets. diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -674,6 +674,8 @@ Type = ELF::SHT_LLVM_BB_ADDR_MAP; else if (TypeName == "llvm_offloading") Type = ELF::SHT_LLVM_OFFLOADING; + else if (TypeName == "llvm_lto") + Type = ELF::SHT_LLVM_LTO; else if (TypeName.getAsInteger(0, Type)) return TokError("unknown section type"); } diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp --- a/llvm/lib/MC/MCSectionELF.cpp +++ b/llvm/lib/MC/MCSectionELF.cpp @@ -169,6 +169,8 @@ OS << "llvm_bb_addr_map_v0"; else if (Type == ELF::SHT_LLVM_OFFLOADING) OS << "llvm_offloading"; + else if (Type == ELF::SHT_LLVM_LTO) + OS << "llvm_lto"; else report_fatal_error("unsupported type 0x" + Twine::utohexstr(Type) + " for section " + getName()); diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -312,6 +312,7 @@ STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_BB_ADDR_MAP_V0); STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_BB_ADDR_MAP); STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_OFFLOADING); + STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_LTO); STRINGIFY_ENUM_CASE(ELF, SHT_GNU_ATTRIBUTES); STRINGIFY_ENUM_CASE(ELF, SHT_GNU_HASH); STRINGIFY_ENUM_CASE(ELF, SHT_GNU_verdef); diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -681,6 +681,7 @@ ECase(SHT_LLVM_BB_ADDR_MAP_V0); ECase(SHT_LLVM_BB_ADDR_MAP); ECase(SHT_LLVM_OFFLOADING); + ECase(SHT_LLVM_LTO); ECase(SHT_GNU_ATTRIBUTES); ECase(SHT_GNU_HASH); ECase(SHT_GNU_verdef); diff --git a/llvm/test/MC/AsmParser/llvm_section_types.s b/llvm/test/MC/AsmParser/llvm_section_types.s --- a/llvm/test/MC/AsmParser/llvm_section_types.s +++ b/llvm/test/MC/AsmParser/llvm_section_types.s @@ -15,6 +15,8 @@ .byte 1 .section .section7,"",@llvm_offloading .byte 1 +.section .section8,"",@llvm_lto +.byte 1 # CHECK: Name: .section1 # CHECK-NEXT: Type: SHT_LLVM_BB_ADDR_MAP @@ -30,3 +32,5 @@ # CHECK-NEXT: Type: SHT_LLVM_DEPENDENT_LIBRARIES # CHECK: Name: .section7 # CHECK-NEXT: Type: SHT_LLVM_OFFLOADING +# CHECK: Name: .section8 +# CHECK-NEXT: Type: SHT_LLVM_LTO diff --git a/llvm/test/MC/ELF/section.s b/llvm/test/MC/ELF/section.s --- a/llvm/test/MC/ELF/section.s +++ b/llvm/test/MC/ELF/section.s @@ -326,3 +326,14 @@ // CHECK-NEXT: Flags [ // CHECK-NEXT: ] // CHECK: } + +.section .llvm.lto,"e",@llvm_lto +// ASM: .section .llvm.lto,"e",@llvm_lto + +// CHECK: Section { +// CHECK: Name: .llvm.lto +// CHECK-NEXT: Type: SHT_LLVM_LTO +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_EXCLUDE +// CHECK-NEXT: ] +// CHECK: } diff --git a/llvm/test/ObjectYAML/ELF/sht-offloading.yaml b/llvm/test/ObjectYAML/ELF/llvm-section-types.yaml rename from llvm/test/ObjectYAML/ELF/sht-offloading.yaml rename to llvm/test/ObjectYAML/ELF/llvm-section-types.yaml --- a/llvm/test/ObjectYAML/ELF/sht-offloading.yaml +++ b/llvm/test/ObjectYAML/ELF/llvm-section-types.yaml @@ -11,18 +11,31 @@ - Name: .llvm.offloading Type: SHT_LLVM_OFFLOADING Flags: [ SHF_EXCLUDE ] + - Name: .llvm.lto + Type: SHT_LLVM_LTO + Flags: [ SHF_EXCLUDE ] # OBJ: Sections [ # OBJ: Section { # OBJ: Index: 1 -# OBJ-NEXT: Name: .llvm.offloading (1) +# OBJ-NEXT: Name: .llvm.offloading # OBJ-NEXT: Type: SHT_LLVM_OFFLOADING (0x6FFF4C0B) # OBJ-NEXT: Flags [ (0x80000000) # OBJ-NEXT: SHF_EXCLUDE (0x80000000) # OBJ-NEXT: ] +# OBJ: Section { +# OBJ: Index: 2 +# OBJ-NEXT: Name: .llvm.lto +# OBJ-NEXT: Type: SHT_LLVM_LTO (0x6FFF4C0C) +# OBJ-NEXT: Flags [ (0x80000000) +# OBJ-NEXT: SHF_EXCLUDE (0x80000000) +# OBJ-NEXT: ] # YAML: Sections: # YAML-NEXT: - Name: .llvm.offloading # YAML-NEXT: Type: SHT_LLVM_OFFLOADING # YAML-NEXT: Flags: [ SHF_EXCLUDE ] +# YAML: - Name: .llvm.lto +# YAML-NEXT: Type: SHT_LLVM_LTO +# YAML-NEXT: Flags: [ SHF_EXCLUDE ] diff --git a/llvm/test/tools/llvm-readobj/ELF/section-types.test b/llvm/test/tools/llvm-readobj/ELF/section-types.test --- a/llvm/test/tools/llvm-readobj/ELF/section-types.test +++ b/llvm/test/tools/llvm-readobj/ELF/section-types.test @@ -59,6 +59,8 @@ # LLVM: Type: SHT_LLVM_PART_EHDR # LLVM: Name: .phdrs # LLVM: Type: SHT_LLVM_PART_PHDR +# LLVM: Name: .llvm.lto +# LLVM: Type: SHT_LLVM_LTO # LLVM: Name: gnu_attributes # LLVM: Type: SHT_GNU_ATTRIBUTES # LLVM: Name: gnu_hash @@ -119,6 +121,7 @@ # GNU-NEXT: .llvm_sympart.f LLVM_SYMPART # GNU-NEXT: part1 LLVM_PART_EHDR # GNU-NEXT: .phdrs LLVM_PART_PHDR +# GNU-NEXT: .llvm.lto LLVM_LTO # GNU-NEXT: gnu_attributes ATTRIBUTES # GNU-NEXT: gnu_hash GNU_HASH # GNU-NEXT: gnu_verdef VERDEF @@ -205,6 +208,8 @@ Type: SHT_LLVM_PART_EHDR - Name: .phdrs Type: SHT_LLVM_PART_PHDR + - Name: .llvm.lto + Type: SHT_LLVM_LTO - Name: gnu_attributes Type: SHT_GNU_ATTRIBUTES - Name: gnu_hash