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: clang linking broken at tip for a specific cgo usage #10015

Closed
mirtchovski opened this issue Feb 26, 2015 · 7 comments

Comments

Projects
None yet
4 participants
@mirtchovski
Copy link
Contributor

commented Feb 26, 2015

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

$ go version
go version devel +28c6648 Wed Feb 25 18:29:42 2015 +0000 darwin/amd64

What operating system and processor architecture are you using?

10.9.5 and 10.10.2

What did you do?

tried to compile the following program:

package main

/*
#include <mach/mach_init.h>
#include <mach/vm_map.h>
*/
import "C"

func main() {
    _ = C.vm_map_t(C.mach_task_self_)
    return
}

What did you expect to see?

$ go version
go version go1.4.1 darwin/amd64
$ go build t.go 
$

What did you see instead?

$ go build t.go
# command-line-arguments
ld: illegal text-relocation to '_mach_task_self_' in /usr/lib/libpthread.dylib from 'main.init' in /var/folders/cm/8q66dvl126x4fjzgs10bxjyc0000gn/T//go-link-SKg1kT/go.o for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
/Users/aam/go/pkg/tool/darwin_amd64/6l: running clang failed: unsuccessful exit status 0x100

@mikioh mikioh changed the title Clang linking broken at tip for a specific cgo usage cmd/ld: clang linking broken at tip for a specific cgo usage Feb 27, 2015

@mikioh

This comment has been minimized.

Copy link
Contributor

commented Feb 27, 2015

With -linkmode external:

go build -v -x -ldflags '-v -linkmode external' test.go
[...]
# command-line-arguments
HEADER = -H1 -T0x2000 -D0x0 -R0x1000
searching for runtime.a in $WORK/runtime.a
searching for runtime.a in /go/pkg/darwin_amd64/runtime.a
 0.04 deadcode
 0.04 pclntab=154533 bytes, funcdata total 44748 bytes
 0.05 dodata
 0.05 symsize = 0
 0.05 symsize = 0
 0.05 reloc
 0.06 reloc
 0.06 asmb
 0.06 codeblk
 0.06 datblk
 0.06 dwarf
 0.06 sym
 0.06 headr
host link: clang -m64 -gdwarf-2 -Wl,-no_pie,-pagezero_size,4000000 -o xxx -Qunused-arguments /var/folders/7d/d3y9vsls2yd880k121jmzcyr0000gn/T//go-link-E55yav/000000.o /var/folders/7d/d3y9vsls2yd880k121jmzcyr0000gn/T//go-link-E55yav/000001.o /var/folders/7d/d3y9vsls2yd880k121jmzcyr0000gn/T//go-link-E55yav/go.o -g -O2 -g -O2 -lpthread
ld: illegal text-relocation to '_mach_task_self_' in /usr/lib/libpthread.dylib from 'main.init' in /var/folders/7d/d3y9vsls2yd880k121jmzcyr0000gn/T//go-link-E55yav/go.o for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
/go/pkg/tool/darwin_amd64/6l: running clang failed: unsuccessful exit status 0x100
@mikioh

This comment has been minimized.

Copy link
Contributor

commented Feb 27, 2015

With linkmode internal:

go build -v -x -ldflags '-v -linkmode internal' test.go
# command-line-arguments
HEADER = -H1 -T0x2000 -D0x0 -R0x1000
searching for runtime.a in $WORK/runtime.a
searching for runtime.a in /go/pkg/darwin_amd64/runtime.a
 0.04 deadcode
 0.05 pclntab=154638 bytes, funcdata total 44748 bytes
 0.05 dodata
 0.05 symsize = 0
 0.05 symsize = 0
 0.05 reloc
 0.05 reloc
 0.05 asmb
 0.05 codeblk
 0.06 datblk
 0.06 dwarf
 0.06 symsize = 0
 0.06 dwarf pass 2.
 0.06 sym
 0.06 headr
 0.06 cpu time
18872 symbols
29152 liveness data
@mirtchovski

This comment has been minimized.

Copy link
Contributor Author

commented Feb 27, 2015

i can confirm that -linkmode internal works for me too.

@mikioh

This comment has been minimized.

Copy link
Contributor

commented Feb 27, 2015

I'm not sure what are you trying to suggest. The mach_task_self_ is a simple environment variable which is prepared by mach_init, and your program doesn't use cgo stuff. Can you please elaborate on your issue? Are you trying to say that the current linker selection of cmd/cgo (see cmd/cgo/doc.go) has some issue?

/cc @ianlancetaylor

@mirtchovski

This comment has been minimized.

Copy link
Contributor Author

commented Feb 27, 2015

I don't know how much more black and white this issue can be: an existing piece of code that used to link fine under 1.4.* does not link at tip. the code is from a real world library which is being used currently:

https://github.com/jondot/gosigar/blob/master/sigar_darwin.go#L129

with '-linkmode internal' the linking is successful in both the test case and the original program that exhibited the issue.

the golang-dev comments preceding the creation of this issue are here:
https://groups.google.com/d/msg/golang-dev/mybQtOb1CfU/ZXEawh6FlRAJ

@mirtchovski

This comment has been minimized.

Copy link
Contributor Author

commented Mar 2, 2015

the latest linker has stopped linking successfully with the -linkmode internal flag:

$ go build -ldflags '-v -linkmode internal' t.go 
# command-line-arguments
HEADER = -H1 -T0x2000 -D0x0 -R0x1000
searching for runtime.a in $WORK/runtime.a
searching for runtime.a in /Users/aam/go/pkg/darwin_amd64/runtime.a
 0.00 deadcode
 0.03 pclntab=154327 bytes, funcdata total 44748 bytes
 0.03 dodata
 0.03 symsize = 0
 0.03 symsize = 0
 0.03 reloc
 0.03 reloc
main.init: mach_task_self_: not defined
 0.03 asmb
 0.03 codeblk
 0.04 datblk
 0.04 dwarf
 0.05 symsize = 0
 0.07 dwarf pass 2.
 0.09 sym
 0.09 headr
main.init: undefined: mach_task_self_
$

external fails as before:

$ go build -ldflags '-v -linkmode external' t.go 
# command-line-arguments
HEADER = -H1 -T0x2000 -D0x0 -R0x1000
searching for runtime.a in $WORK/runtime.a
searching for runtime.a in /Users/aam/go/pkg/darwin_amd64/runtime.a
 0.00 deadcode
 0.01 pclntab=154247 bytes, funcdata total 44748 bytes
 0.01 dodata
 0.01 symsize = 0
 0.01 symsize = 0
 0.01 reloc
 0.01 reloc
 0.02 asmb
 0.02 codeblk
 0.02 datblk
 0.02 dwarf
 0.02 sym
 0.03 headr
host link: clang -m64 -gdwarf-2 -Wl,-no_pie,-pagezero_size,4000000 -o t -Qunused-arguments /var/folders/cm/8q66dvl126x4fjzgs10bxjyc0000gn/T/go-link-741086293/000000.o /var/folders/cm/8q66dvl126x4fjzgs10bxjyc0000gn/T/go-link-741086293/000001.o /var/folders/cm/8q66dvl126x4fjzgs10bxjyc0000gn/T/go-link-741086293/go.o -g -O2 -g -O2 -lpthread
/Users/aam/go/pkg/tool/darwin_amd64/6l: running clang failed: exit status 1
ld: illegal text-relocation to '_mach_task_self_' in /usr/lib/libpthread.dylib from 'main.init' in /var/folders/cm/8q66dvl126x4fjzgs10bxjyc0000gn/T/go-link-741086293/go.o for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$
$ go version
go version devel +5324cf2 Mon Mar 2 08:30:39 2015 +0000 darwin/amd64
$

@rsc rsc added this to the Go1.5Maybe milestone Apr 10, 2015

@rsc rsc changed the title cmd/ld: clang linking broken at tip for a specific cgo usage cmd/link: clang linking broken at tip for a specific cgo usage Jun 8, 2015

@rsc

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2015

Dup of #9411, CL sent for that.

@rsc rsc closed this Jun 29, 2015

@mikioh mikioh modified the milestones: Go1.5, Go1.5Maybe Jul 9, 2015

@golang golang locked and limited conversation to collaborators Jul 11, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.