Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -14,6 +14,7 @@ #include "LinkerScript.h" #include "SymbolTable.h" #include "Symbols.h" +#include "SyntheticSections.h" #include "lld/Support/Memory.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Bitcode/BitcodeReader.h" @@ -336,8 +337,14 @@ switch (Sec.sh_type) { case SHT_ARM_ATTRIBUTES: - // FIXME: ARM meta-data section. At present attributes are ignored, - // they can be used to reason about object compatibility. + // FIXME: ARM meta-data section. Retain the first attribute section + // we see. The eglibc ARM dynamic loaders require the presence of an + // attribute section for dlopen to work. + // In a full implementation we would merge all attribute sections. + if (In::ARMAttributes == nullptr) { + In::ARMAttributes = make>(this, &Sec, Name); + return In::ARMAttributes; + } return &InputSection::Discarded; case SHT_RELA: case SHT_REL: { Index: ELF/SyntheticSections.h =================================================================== --- ELF/SyntheticSections.h +++ ELF/SyntheticSections.h @@ -667,6 +667,7 @@ // Linker generated sections which can be used as inputs. template struct In { + static InputSection *ARMAttributes; static BuildIdSection *BuildId; static InputSection *Common; static DynamicSection *Dynamic; @@ -695,6 +696,7 @@ static VersionNeedSection *VerNeed; }; +template InputSection *In::ARMAttributes; template BuildIdSection *In::BuildId; template InputSection *In::Common; template DynamicSection *In::Dynamic; Index: test/ELF/Inputs/arm-attributes1.s =================================================================== --- test/ELF/Inputs/arm-attributes1.s +++ test/ELF/Inputs/arm-attributes1.s @@ -1,20 +1,4 @@ -// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o -// RUN: ld.lld %t.o -o %t -// RUN: llvm-readobj -s %t | FileCheck %s -// RUN: ld.lld %t.o -shared -o %t2 -// RUN: llvm-readobj -s %t2 | FileCheck %s -// RUN: ld.lld %t.o -r -o %t3 -// RUN: llvm-readobj -s %t3 | FileCheck %s - -// The .ARM.attributes section should be removed from executables and -// shared objects. - -// At present we remove it from the -r object output as well which isn't ideal. -// Unfortunately combining per-object attributes cannot be safely done by just -// concatentation of input sections. - -// CHECK-NOT: Name: .ARM.attributes -// REQUIRES: arm +// Input that generates an object with a populated SHT_ARM_ATTRIBUTES section .text .syntax unified .eabi_attribute 67, "2.09" @ Tag_conformance @@ -38,8 +22,8 @@ .eabi_attribute 26, 2 @ Tag_ABI_enum_size .eabi_attribute 14, 0 @ Tag_ABI_PCS_R9_use .eabi_attribute 68, 1 @ Tag_Virtualization_use - .globl _start + .globl func .p2align 2 - .type _start,%function -_start: + .type func,%function +func: bx lr Index: test/ELF/arm-attributes.s =================================================================== --- /dev/null +++ test/ELF/arm-attributes.s @@ -0,0 +1,183 @@ +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/arm-attributes1.s -o %t1.o +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t2.o + +// RUN: ld.lld %t1.o %t2.o -o %t +// RUN: llvm-readobj -arm-attributes %t | FileCheck %s +// RUN: ld.lld %t1.o %t2.o -shared -o %t2 +// RUN: llvm-readobj -arm-attributes %t2 | FileCheck %s +// RUN: ld.lld %t1.o %t2.o -r -o %t3 +// RUN: llvm-readobj -arm-attributes %t3 | FileCheck %s +// REQUIRES: arm + +// Check that we retain only 1 SHT_ARM_ATTRIBUTES section. At present we do not +// try and merge or use the contents of SHT_ARM_ATTRIBUTES sections. We just +// pass the first one through. + .text + .syntax unified + .eabi_attribute 67, "2.09" @ Tag_conformance + .cpu cortex-a8 + .eabi_attribute 6, 10 @ Tag_CPU_arch + .eabi_attribute 7, 65 @ Tag_CPU_arch_profile + .eabi_attribute 8, 1 @ Tag_ARM_ISA_use + .eabi_attribute 9, 2 @ Tag_THUMB_ISA_use + .fpu neon + .eabi_attribute 15, 1 @ Tag_ABI_PCS_RW_data + .eabi_attribute 16, 1 @ Tag_ABI_PCS_RO_data + .eabi_attribute 17, 2 @ Tag_ABI_PCS_GOT_use + .eabi_attribute 20, 1 @ Tag_ABI_FP_denormal + .eabi_attribute 21, 1 @ Tag_ABI_FP_exceptions + .eabi_attribute 23, 3 @ Tag_ABI_FP_number_model + .eabi_attribute 34, 1 @ Tag_CPU_unaligned_access + .eabi_attribute 24, 1 @ Tag_ABI_align_needed + .eabi_attribute 25, 1 @ Tag_ABI_align_preserved + .eabi_attribute 38, 1 @ Tag_ABI_FP_16bit_format + .eabi_attribute 18, 4 @ Tag_ABI_PCS_wchar_t + .eabi_attribute 26, 2 @ Tag_ABI_enum_size + .eabi_attribute 14, 0 @ Tag_ABI_PCS_R9_use + .eabi_attribute 68, 1 @ Tag_Virtualization_use + .globl _start + .p2align 2 + .type _start,%function +_start: + .globl func + bl func + bx lr + +// CHECK: BuildAttributes { +// CHECK-NEXT: FormatVersion: 0x41 +// CHECK-NEXT: Section 1 { +// CHECK-NEXT: SectionLength: 72 +// CHECK-NEXT: Vendor: aeabi +// CHECK-NEXT: Tag: Tag_File (0x1) +// CHECK-NEXT: Size: 62 +// CHECK-NEXT: FileAttributes { +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 67 +// CHECK-NEXT: TagName: conformance +// CHECK-NEXT: Value: 2.09 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 5 +// CHECK-NEXT: TagName: CPU_name +// CHECK-NEXT: Value: cortex-a8 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 6 +// CHECK-NEXT: Value: 10 +// CHECK-NEXT: TagName: CPU_arch +// CHECK-NEXT: Description: ARM v7 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 7 +// CHECK-NEXT: Value: 65 +// CHECK-NEXT: TagName: CPU_arch_profile +// CHECK-NEXT: Description: Application +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 8 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ARM_ISA_use +// CHECK-NEXT: Description: Permitted +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 9 +// CHECK-NEXT: Value: 2 +// CHECK-NEXT: TagName: THUMB_ISA_use +// CHECK-NEXT: Description: Thumb-2 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 10 +// CHECK-NEXT: Value: 3 +// CHECK-NEXT: TagName: FP_arch +// CHECK-NEXT: Description: VFPv3 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 12 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: Advanced_SIMD_arch +// CHECK-NEXT: Description: NEONv1 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 14 +// CHECK-NEXT: Value: 0 +// CHECK-NEXT: TagName: ABI_PCS_R9_use +// CHECK-NEXT: Description: v6 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 15 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_PCS_RW_data +// CHECK-NEXT: Description: PC-relative +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 16 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_PCS_RO_data +// CHECK-NEXT: Description: PC-relative +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 17 +// CHECK-NEXT: Value: 2 +// CHECK-NEXT: TagName: ABI_PCS_GOT_use +// CHECK-NEXT: Description: GOT-Indirect +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 18 +// CHECK-NEXT: Value: 4 +// CHECK-NEXT: TagName: ABI_PCS_wchar_t +// CHECK-NEXT: Description: 4-byte +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 20 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_FP_denormal +// CHECK-NEXT: Description: IEEE-754 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 21 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_FP_exceptions +// CHECK-NEXT: Description: IEEE-754 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 23 +// CHECK-NEXT: Value: 3 +// CHECK-NEXT: TagName: ABI_FP_number_model +// CHECK-NEXT: Description: IEEE-754 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 24 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_align_needed +// CHECK-NEXT: Description: 8-byte alignment +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 25 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_align_preserved +// CHECK-NEXT: Description: 8-byte data alignment +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 26 +// CHECK-NEXT: Value: 2 +// CHECK-NEXT: TagName: ABI_enum_size +// CHECK-NEXT: Description: Int32 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 34 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: CPU_unaligned_access +// CHECK-NEXT: Description: v6-style +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 38 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: ABI_FP_16bit_format +// CHECK-NEXT: Description: IEEE-754 +// CHECK-NEXT: } +// CHECK-NEXT: Attribute { +// CHECK-NEXT: Tag: 68 +// CHECK-NEXT: Value: 1 +// CHECK-NEXT: TagName: Virtualization_use +// CHECK-NEXT: Description: TrustZone +// CHECK-NEXT: }