summaryrefslogtreecommitdiff
path: root/cmd/extract_linker/main.go
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2021-06-11 17:57:09 -0700
committer Colin Cross <ccross@android.com> 2021-06-11 17:57:09 -0700
commit009f3df380e22e9f357ceed75ad24cdae5896058 (patch)
tree2a459b4afd893a56aadc87e46a432582d7682cb8 /cmd/extract_linker/main.go
parentf04eb99acce1c95c9ecc9da501898fb8ad00731d (diff)
Give extracted linker sections pretty names
Replace .linker.sect0, etc. with .linker, .linker.text, .linker.data and .linker.data.rel.ro by extracting the name of the first section in each program header. Test: build and run host bionic binary Change-Id: I25107547536a3a3963fdeb311c45a7ee53c0bc45
Diffstat (limited to 'cmd/extract_linker/main.go')
-rw-r--r--cmd/extract_linker/main.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/cmd/extract_linker/main.go b/cmd/extract_linker/main.go
index ea0bf4eed..d62dea1c0 100644
--- a/cmd/extract_linker/main.go
+++ b/cmd/extract_linker/main.go
@@ -61,8 +61,15 @@ func main() {
continue
}
- sectionName := fmt.Sprintf(".linker.sect%d", load)
- symName := fmt.Sprintf("__dlwrap_linker_sect%d", load)
+ var progName string
+ progSection := progToFirstSection(prog, ef.Sections)
+ if progSection != nil {
+ progName = progSection.Name
+ } else {
+ progName = fmt.Sprintf(".sect%d", load)
+ }
+ sectionName := ".linker" + progName
+ symName := "__dlwrap_linker" + strings.ReplaceAll(progName, ".", "_")
flags := ""
if prog.Flags&elf.PF_W != 0 {
@@ -125,3 +132,12 @@ func bytesToAsm(asm io.Writer, buf []byte) {
}
fmt.Fprintln(asm)
}
+
+func progToFirstSection(prog *elf.Prog, sections []*elf.Section) *elf.Section {
+ for _, section := range sections {
+ if section.Addr == prog.Vaddr {
+ return section
+ }
+ }
+ return nil
+}