Skip to contentSkip to conversation

objtool: use sh_info to find the base for .rela sections

PATCH In review Sami Tolvanen 2 participants 2 messages Apr 21, 2020 objtool

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 objtool: use sh_info to find the base for .rela sections

ELF doesn't require .rela section names to match the base section. Use the section index in sh_info to find the section instead of looking it up by name.

LLD, for example, generates a .rela section that doesn't match the base section name when we merge sections in a linker script for a binary compiled with -ffunction-sections.

---
 tools/objtool/elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/objtool/elf.c +1 -1
index 09ddc8f1def3..73cfe45975c8 100644
@@ -468,7 +468,7 @@ static int read_relas(struct elf *elf)
 		if (sec->sh.sh_type != SHT_RELA)
 			continue;
 
-		sec->base = find_section_by_name(elf, sec->name + 5);
+		sec->base = find_section_by_index(elf, sec->sh.sh_info);
 		if (!sec->base) {
 			WARN("can't find base section for rela section %s",
 			     sec->name);

base-commit: ae83d0b416db002fe95601e7f97f64b59514d936

Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Sami Tolvanen

ELF doesn't require .rela section names to match the base section. Use the section index in sh_info to find the section instead of looking it up by name.

LLD, for example, generates a .rela section that doesn't match the base section name when we merge sections in a linker script for a binary compiled with -ffunction-sections.

-Kees

Quoted 22 lines
---
 tools/objtool/elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/objtool/elf.c +1 -1
index 09ddc8f1def3..73cfe45975c8 100644
@@ -468,7 +468,7 @@ static int read_relas(struct elf *elf)
 		if (sec->sh.sh_type != SHT_RELA)
 			continue;
 
-		sec->base = find_section_by_name(elf, sec->name + 5);
+		sec->base = find_section_by_index(elf, sec->sh.sh_info);
 		if (!sec->base) {
 			WARN("can't find base section for rela section %s",
 			     sec->name);

base-commit: ae83d0b416db002fe95601e7f97f64b59514d936

Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
Signature · 1 line
Kees Cook