[MC] Set SHF_INFO_LINK on SHT_REL/SHT_RELA sections

sh_info links to a section, therefore SHF_INFO_LINK should be set as GNU as
does. The issue has been benign because linkers kindly combines relocation
sections w/ and w/o the flag.
This commit is contained in:
Fangrui Song 2021-09-02 01:00:51 -07:00
parent cb6b658a40
commit dfb7518df1
23 changed files with 28 additions and 5 deletions

View File

@ -796,7 +796,7 @@ MCSectionELF *ELFWriter::createRelocationSection(MCContext &Ctx,
else
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
unsigned Flags = 0;
unsigned Flags = ELF::SHF_INFO_LINK;
if (Sec.getFlags() & ELF::SHF_GROUP)
Flags = ELF::SHF_GROUP;

View File

@ -18,6 +18,7 @@ f1:
// CHECK: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -55,6 +55,7 @@ f:
// CHECK-NEXT: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -36,6 +36,7 @@ f:
// CHECK: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -38,6 +38,7 @@ f:
// CHECK: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -37,6 +37,7 @@ f:
// CHECK: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -33,6 +33,7 @@ f:
// CHECK: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -38,6 +38,7 @@ f:
// CHECK-NEXT: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -33,6 +33,7 @@ f:
// CHECK: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -38,6 +38,7 @@ f:
// CHECK-NEXT: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -48,6 +48,7 @@ f:
// CHECK-NEXT: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -33,6 +33,7 @@ f:
// CHECK-NEXT: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -40,6 +40,7 @@ f:
// CHECK-NEXT: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -34,6 +34,7 @@ f:
// CHECK-NEXT: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -38,6 +38,7 @@ f:
// CHECK-NEXT: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -38,6 +38,7 @@ f:
// CHECK-NEXT: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -40,6 +40,7 @@ f:
// CHECK: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -41,6 +41,7 @@ f:
// CHECK: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -358,6 +358,7 @@ f37:
// CHECK: Name: .rela.eh_frame
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -33,7 +33,8 @@ late3:
# CHECK: Name: .rel.llvm.call-graph-profile (28)
# CHECK-NEXT: Type: SHT_REL (0x9)
# CHECK-NEXT: Flags [ (0x0)
# CHECK-NEXT: Flags [ (0x40)
# CHECK-NEXT: SHF_INFO_LINK
# CHECK-NEXT: ]
# CHECK-NEXT: Address: 0x0
# CHECK-NEXT: Offset: 0x140

View File

@ -11,6 +11,7 @@
// CHECK: Name: .rela.text
// CHECK-NEXT: Type: SHT_RELA
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -19,7 +19,8 @@ defined3:
// CHECK: Index:
// CHECK: Name: .rela.text
// CHECK-NEXT: Type: SHT_RELA (0x4)
// CHECK-NEXT: Flags [ (0x0)
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_INFO_LINK
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// CHECK-NEXT: Offset:

View File

@ -40,7 +40,8 @@ _proc:
# STATIC: Section {
# STATIC: Name: .rela.eh_frame
# STATIC-NEXT: Type: SHT_RELA
# STATIC-NEXT: Flags [ (0x0)
# STATIC-NEXT: Flags [
# STATIC-NEXT: SHF_INFO_LINK
# STATIC-NEXT: ]
# STATIC-NEXT: Address:
# STATIC-NEXT: Offset:
@ -81,7 +82,8 @@ _proc:
# PIC: Section {
# PIC: Name: .rela.eh_frame
# PIC-NEXT: Type: SHT_RELA
# PIC-NEXT: Flags [ (0x0)
# PIC-NEXT: Flags [
# PIC-NEXT: SHF_INFO_LINK
# PIC-NEXT: ]
# PIC-NEXT: Address:
# PIC-NEXT: Offset: