[lld] 048f350 - Move HIP fatbin sections farther away from .text
Siu Chi Chan via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 6 08:18:53 PDT 2024
Author: Siu Chi Chan
Date: 2024-08-06T15:17:59Z
New Revision: 048f35037779763963c4b4478a0884e828ea9538
URL: https://github.com/llvm/llvm-project/commit/048f35037779763963c4b4478a0884e828ea9538
DIFF: https://github.com/llvm/llvm-project/commit/048f35037779763963c4b4478a0884e828ea9538.diff
LOG: 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.
Added:
lld/test/ELF/hip-section-layout.s
Modified:
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 5bee84a5cf81a..4c0b4df5bea17 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -632,6 +632,7 @@ static bool isRelroSection(const OutputSection *sec) {
enum RankFlags {
RF_NOT_ADDR_SET = 1 << 27,
RF_NOT_ALLOC = 1 << 26,
+ RF_HIP_FATBIN = 1 << 19,
RF_PARTITION = 1 << 18, // Partition number (8 bits)
RF_LARGE_ALT = 1 << 15,
RF_WRITE = 1 << 14,
@@ -729,6 +730,15 @@ unsigned elf::getSectionRank(OutputSection &osec) {
if (osec.type == SHT_NOBITS)
rank |= RF_BSS;
+ // Put HIP fatbin related sections further away to avoid wasting relocation
+ // range to jump over them. Make sure .hip_fatbin is the furthest.
+ if (osec.name == ".hipFatBinSegment")
+ rank |= RF_HIP_FATBIN;
+ if (osec.name == ".hip_gpubin_handle")
+ rank |= RF_HIP_FATBIN | 2;
+ if (osec.name == ".hip_fatbin")
+ rank |= RF_HIP_FATBIN | RF_WRITE | 3;
+
// Some architectures have additional ordering restrictions for sections
// within the same PT_LOAD.
if (config->emachine == EM_PPC64) {
diff --git a/lld/test/ELF/hip-section-layout.s b/lld/test/ELF/hip-section-layout.s
new file mode 100644
index 0000000000000..c76df50919e6d
--- /dev/null
+++ b/lld/test/ELF/hip-section-layout.s
@@ -0,0 +1,39 @@
+# REQUIRES: x86
+## Test HIP specific sections layout.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux --defsym=HIP_SECTIONS=1 --defsym=NON_HIP_SECTIONS=1 %s -o %t.o
+# RUN: ld.lld %t.o -o %t.out
+# RUN: llvm-readobj --sections %t.out | FileCheck %s
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux --defsym=NON_HIP_SECTIONS=1 %s -o %t.1.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux --defsym=HIP_SECTIONS=1 %s -o %t.2.o
+# RUN: ld.lld %t.1.o %t.2.o -o %t.s.out
+# RUN: llvm-readobj --sections %t.s.out | FileCheck %s
+
+.ifdef HIP_SECTIONS
+.section .hipFatBinSegment,"aw", at progbits; .space 1
+.section .hip_gpubin_handle,"aw", at progbits; .space 1
+.section .hip_fatbin,"a", at progbits; .space 1
+.endif
+
+.ifdef NON_HIP_SECTIONS
+.global _start
+.text
+_start:
+.section .bss,"aw", at nobits; .space 1
+.section .debug_info,"", at progbits
+.section .debug_line,"", at progbits
+.section .debug_str,"MS", at progbits,1
+.endif
+
+# Check that the HIP sections are placed towards the end but before non allocated sections
+
+// CHECK: Name: .text
+// CHECK: Name: .bss
+// CHECK: Name: .hipFatBinSegment
+// CHECK: Name: .hip_gpubin_handle
+// CHECK: Name: .hip_fatbin
+// CHECK: Name: .debug_info
+// CHECK: Name: .debug_line
+// CHECK: Name: .debug_str
+
More information about the llvm-commits
mailing list