proc: fix dynamic library loading with musl loader (#3621)
With the glibc loader the link map entry for the static executable has an empty name field and address equal to 0x0. This case was already handled by the check in bininfo.go AddImage for names to be valid paths. With the musl loader however the first entry, corresponding to the static executable, has a valid path with address equal to 0x0, since we record a real address for the image corresponding to the static executable this results in having two entries for the executable when musl is used to link go programs. Change the code scanning the debug link map so that the first entry is skipped if it has address equal to zero. Fixes #3617
This commit is contained in:
parent
bf627d0f7d
commit
88380654fe
@ -165,6 +165,8 @@ func ElfUpdateSharedObjects(p proc.Process) error {
|
|||||||
|
|
||||||
libs := []string{}
|
libs := []string{}
|
||||||
|
|
||||||
|
first := true
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if r_map == 0 {
|
if r_map == 0 {
|
||||||
break
|
break
|
||||||
@ -176,8 +178,13 @@ func ElfUpdateSharedObjects(p proc.Process) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
bi.AddImage(lm.name, lm.addr)
|
if !first || lm.addr != 0 {
|
||||||
|
// First entry is the executable, we don't need to add it, and doing so
|
||||||
|
// can cause duplicate entries due to base address mismatches.
|
||||||
|
bi.AddImage(lm.name, lm.addr)
|
||||||
|
}
|
||||||
libs = append(libs, lm.name)
|
libs = append(libs, lm.name)
|
||||||
|
first = false
|
||||||
r_map = lm.next
|
r_map = lm.next
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2625,7 +2625,7 @@ func libraries(t *Term, ctx callContext, args string) error {
|
|||||||
for i := range libs {
|
for i := range libs {
|
||||||
fmt.Fprintf(t.stdout, "%"+strconv.Itoa(d)+"d. %#x %s\n", i, libs[i].Address, libs[i].Path)
|
fmt.Fprintf(t.stdout, "%"+strconv.Itoa(d)+"d. %#x %s\n", i, libs[i].Address, libs[i].Path)
|
||||||
if libs[i].LoadError != "" {
|
if libs[i].LoadError != "" {
|
||||||
fmt.Fprintf(t.stdout, " Load error: %s", libs[i].LoadError)
|
fmt.Fprintf(t.stdout, " Load error: %s\n", libs[i].LoadError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user