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
Milestone

Comments

@shachaf
Copy link

@shachaf 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

This comment has been minimized.

Copy link
Contributor

@agnivade agnivade commented Jul 30, 2019

@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
@ianlancetaylor ianlancetaylor added this to the Go1.14 milestone Jul 30, 2019
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 30, 2019

Thanks. I agree that this should be fixed.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jul 31, 2019

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

@gopherbot gopherbot closed this in 12dbd20 Aug 31, 2019
@shachaf

This comment has been minimized.

Copy link
Author

@shachaf 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 added 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

This comment has been minimized.

Copy link
Contributor

@cuonglm cuonglm commented Sep 1, 2019

t4n6a1ka added 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.