Skip to content

Commit 2bf4f3e

Browse files
scchanDavid Salinas
authored andcommitted
Move HIP fatbin sections farther away from .text
This would avoid wasting relocation range to jump over the HIP fatbin sections and therefore alleviate relocation overflow pressure. Change-Id: I98d67e0f33a893eb48e2f47300702d75c4da6e1f
1 parent 5bd43fa commit 2bf4f3e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lld/ELF/Writer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ static bool isRelroSection(const OutputSection *sec) {
623623
enum RankFlags {
624624
RF_NOT_ADDR_SET = 1 << 27,
625625
RF_NOT_ALLOC = 1 << 26,
626+
RF_HIP_FATBIN = 1 << 19,
626627
RF_PARTITION = 1 << 18, // Partition number (8 bits)
627628
RF_LARGE_ALT = 1 << 15,
628629
RF_WRITE = 1 << 14,
@@ -720,6 +721,15 @@ unsigned elf::getSectionRank(OutputSection &osec) {
720721
if (osec.type == SHT_NOBITS)
721722
rank |= RF_BSS;
722723

724+
// Put HIP fatbin related sections further away to avoid wasting relocation
725+
// range to jump over them. Make sure .hip_fatbin is the furthest.
726+
if (osec.name == ".hipFatBinSegment")
727+
rank |= RF_HIP_FATBIN;
728+
if (osec.name == ".hip_gpubin_handle")
729+
rank |= RF_HIP_FATBIN | 2;
730+
if (osec.name == ".hip_fatbin")
731+
rank |= RF_HIP_FATBIN | RF_WRITE | 3;
732+
723733
// Some architectures have additional ordering restrictions for sections
724734
// within the same PT_LOAD.
725735
if (config->emachine == EM_PPC64) {

lld/test/ELF/hip-section-layout.s

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# REQUIRES: x86
2+
## Test HIP specific sections layout.
3+
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux --defsym=HIP_SECTIONS=1 --defsym=NON_HIP_SECTIONS=1 %s -o %t.o
5+
# RUN: ld.lld %t.o -o %t.out
6+
# RUN: llvm-readobj --sections %t.out | FileCheck %s
7+
8+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux --defsym=NON_HIP_SECTIONS=1 %s -o %t.1.o
9+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux --defsym=HIP_SECTIONS=1 %s -o %t.2.o
10+
# RUN: ld.lld %t.1.o %t.2.o -o %t.s.out
11+
# RUN: llvm-readobj --sections %t.s.out | FileCheck %s
12+
13+
.ifdef HIP_SECTIONS
14+
.section .hipFatBinSegment,"aw",@progbits; .space 1
15+
.section .hip_gpubin_handle,"aw",@progbits; .space 1
16+
.section .hip_fatbin,"a",@progbits; .space 1
17+
.endif
18+
19+
.ifdef NON_HIP_SECTIONS
20+
.global _start
21+
.text
22+
_start:
23+
.section .bss,"aw",@nobits; .space 1
24+
.section .debug_info,"",@progbits
25+
.section .debug_line,"",@progbits
26+
.section .debug_str,"MS",@progbits,1
27+
.endif
28+
29+
# Check that the HIP sections are placed towards the end but before non allocated sections
30+
31+
// CHECK: Name: .text
32+
// CHECK: Name: .bss
33+
// CHECK: Name: .hipFatBinSegment
34+
// CHECK: Name: .hip_gpubin_handle
35+
// CHECK: Name: .hip_fatbin
36+
// CHECK: Name: .debug_info
37+
// CHECK: Name: .debug_line
38+
// CHECK: Name: .debug_str
39+

0 commit comments

Comments
 (0)