Skip to content

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

Closed
@gopherbot

Description

@gopherbot

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions