Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: ELF linker generates incorrect local dynamic symbol count #33358

Closed
shachaf opened this issue Jul 30, 2019 · 5 comments
Closed

cmd/link: ELF linker generates incorrect local dynamic symbol count #33358

shachaf opened this issue Jul 30, 2019 · 5 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@shachaf
Copy link

shachaf commented Jul 30, 2019

When generating a dynamically-linked ELF file, the ".dynsym" section's info field specifies the number of local symbols. It currently seems to generate 0, but symbol 0 is reserved and always local, so the value should be at least 1. readelf (from GNU binutils 2.30) reports this warning.

What version of Go are you using (go version)?

$ go version
go version go1.10.4 linux/amd64

Does this issue reproduce with the latest release?

It is present in master at the time of writing.

See https://github.com/golang/go/blob/master/src/cmd/link/internal/ld/elf.go#L1934

What operating system and processor architecture are you using (go env)?

linux_amd64

What did you do?

Build a program that uses dynamic linking. E.g.

package main

import "net"

func main() {
	net.Dial("", "")
}

And look at the .dynsym info field.

What did you expect to see?

.dynsym info field >= 1.

What did you see instead?

.dynsym info field 0, and no warnings from readelf.

  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [11] .dynsym           DYNSYM           000000000052c1e0  0012c1e0
       0000000000000390  0000000000000018   A      10     0     8
readelf: Warning: local symbol 0 found at index >= .dynsym's sh_info value of 0
@agnivade
Copy link
Contributor

@ianlancetaylor

@agnivade agnivade changed the title ELF linker generates incorrect local dynamic symbol count cmd/link: ELF linker generates incorrect local dynamic symbol count Jul 30, 2019
@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 30, 2019
@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Jul 30, 2019
@ianlancetaylor ianlancetaylor added this to the Go1.14 milestone Jul 30, 2019
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 30, 2019
@ianlancetaylor
Copy link
Contributor

Thanks. I agree that this should be fixed.

@gopherbot
Copy link

Change https://golang.org/cl/187979 mentions this issue: cmd/link: set .dynsym info field

@shachaf
Copy link
Author

shachaf commented Aug 31, 2019

I suspect this won't happen if there's a .dynsym section, but I should mention that if there are no global symbols, this code won't set sh.info (it should be set to the local symbol count regardless).

tomocy pushed a commit to tomocy/go that referenced this issue Sep 1, 2019
.dynsym section info field is the index of first non-local symbol, mean
the number of local symbols.

The go linker have never ever set it before, so just set it.

Fixes golang#33358

Change-Id: Ifde2deb7c15471b04d565861f5d81daffb0c0d3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/187979
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@cuonglm
Copy link
Member

cuonglm commented Sep 1, 2019

@shachaf good catch, fixed in https://go-review.googlesource.com/c/go/+/192600

t4n6a1ka pushed a commit to t4n6a1ka/go that referenced this issue Sep 5, 2019
.dynsym section info field is the index of first non-local symbol, mean
the number of local symbols.

The go linker have never ever set it before, so just set it.

Fixes golang#33358

Change-Id: Ifde2deb7c15471b04d565861f5d81daffb0c0d3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/187979
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Aug 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants