Skip to content

cmd/8l: unexpected GOT reloc for non-dynamic symbol #4782

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

Closed
gopherbot opened this issue Feb 10, 2013 · 2 comments
Closed

cmd/8l: unexpected GOT reloc for non-dynamic symbol #4782

gopherbot opened this issue Feb 10, 2013 · 2 comments
Milestone

Comments

@gopherbot
Copy link
Contributor

by happyalu:

When using cgo to compile for linux/386 on a linux/amd64 host, I get this error:
unexpected GOT reloc for non-dynamic symbol. 

Small Code to reproduce the error is at http://play.golang.org/p/WfasIPKzKH

Running:
$ GOARCH=386 go build

produces:
unexpected GOT reloc for non-dynamic symbol x

The reloc in question here is a R_386_GOT32 reloc for the global 'x'.

--- Disassembly Snippet
00000020 <g>:

  20:   53                      push   %ebx
  21:   e8 fc ff ff ff          call   22 <g+0x2>
            22: R_386_PC32  __x86.get_pc_thunk.bx
  26:   81 c3 02 00 00 00       add    $0x2,%ebx
            28: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
  2c:   83 ec 08                sub    $0x8,%esp
  2f:   e8 fc ff ff ff          call   30 <g+0x10>
            30: R_386_PLT32 f
  34:   3b 83 00 00 00 00       cmp    0x0(%ebx),%eax
            36: R_386_GOT32 x
  3a:   0f 94 c0                sete   %al
  3d:   83 c4 08                add    $0x8,%esp
  40:   0f b6 c0                movzbl %al,%eax
  43:   5b                      pop    %ebx
  44:   c3                      ret    

---

cmd/8l/asm.c seems to handle only the MOVL instruction for R_386_GOT32 reloc of
non-dynamic symbols. The instruction this code generates is CMP.

I was able to work around this problem by basically adding a GOT entry for the symbol,
as if it were a dynamic symbol. That seemed to work both for this minimal example and
the real code I was trying to get working. 

But I not quite sure what the actual fix here is :)

Which version are you using?  (run 'go version')
go version devel +7cb3730e3f37 Fri Feb 08 19:24:50 2013 +0400 linux/amd64
@gopherbot
Copy link
Contributor Author

Comment 1 by happyalu:

This is similar to issue #4272. 
Following the instructions there, I tested the failing code (see description of issue)
and see this:
$ GOARCH=386 go run check.go 
# command-line-arguments
�(.text): unexpected GOT reloc for non-dynamic symbol x
$ GOARCH=386 go run -ldflags=-hostobj check.go 
Hello:  1
Thus this issue could be merged with issue #4069.

@rsc
Copy link
Contributor

rsc commented Mar 12, 2013

Comment 2:

Fantastic. Now we just have to finish 4069. :-)

Status changed to Duplicate.

Merged into issue #4069.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants