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/go: dylib built as buildmode=c-shared causes 'overlapping segments' after codesign by Xcode on OS X #12700

Open
albertjin opened this Issue Sep 20, 2015 · 8 comments

Comments

Projects
None yet
8 participants
@albertjin

albertjin commented Sep 20, 2015

Go 1.5.1 on OS X 10.10.5 with Xcode 7

  1. Save test code as dy.go

    package main
    
    import "C"
    
    import (
       "fmt"
    )
    
    //export PrintHello
    func PrintHello() {
        fmt.Println("hello")
    }
    
    func main() {
    }
  2. Build

    go build -v -o dy.dylib -buildmode=c-shared dy.go
    
  3. Use it in an Xcode app project

    Add dy.dylib to an Xcode app project for linking and setup the project in TARGETS > [targetname] > Build Phases
    dy.lib to be bundled in Xcode
    Notice that the option Code Sign on Copy is selected, otherwise the whole bundle cannot pass code sign. In the screenshot, the text for Run Script is

    install_name_tool -change dy.dylib @loader_path/../Frameworks/dy.dylib "$TARGET_BUILD_DIR/$TARGET_NAME.app/Contents/MacOS/$PRODUCT_NAME"
    
  4. Build the Xcode project successfully and run it
    Here is the error,

    dyld: Library not loaded: @loader_path/../Frameworks/dy.dylib
     Referenced from: /Users/albert/Library/Developer/Xcode/DerivedData/qr-cavcmuynmurgdxafrfnfvdoaxezo/Build/Products/Debug/qr.app/Contents/MacOS/qr
    Reason: no suitable image found.  Did find:
    /Users/albert/Library/Developer/Xcode/DerivedData/qr-cavcmuynmurgdxafrfnfvdoaxezo/Build/Products/Debug/qr.app/Contents/MacOS/../Frameworks/dy.dylib: overlapping segments
    /Users/albert/Library/Developer/Xcode/DerivedData/qr-cavcmuynmurgdxafrfnfvdoaxezo/Build/Products/Debug/qr.app/Contents/MacOS/../Frameworks/dy.dylib: overlapping segments
    

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Sep 21, 2015

@rakyll

This comment has been minimized.

Member

rakyll commented Sep 21, 2015

/cc @crawshaw

@rsc

This comment has been minimized.

Contributor

rsc commented Nov 23, 2015

Does anyone know any more about what is going wrong here?

@glycerine

This comment has been minimized.

glycerine commented Dec 14, 2015

just a guess, the -o dy.dylib looks suspicious, as I expect a .so as output.

http://stackoverflow.com/questions/2339679/what-are-the-differences-between-so-and-dylib-on-osx

"The Mach-O object file format used by Mac OS X for executables and libraries distinguishes between shared libraries and dynamically loaded modules. Use otool -hv some_file to see the filetype of some_file."

@rsc rsc modified the milestones: Unplanned, Go1.6 Dec 17, 2015

@Qix-

This comment has been minimized.

Qix- commented Apr 4, 2016

Sooooo this is a huge 👎 on Go's part. How do you create a .dylib? This seems like a glaring feature hole.

@glycerine

This comment has been minimized.

glycerine commented Apr 5, 2016

@qix, the shared library build modes are a "still being implemented" feature (especially on OSX) -- only some of the new buildmodes that Ian defined in the spec are implemented, and support across platforms is still quite limited.

You can help by playing with the feature and reporting rough edges in your specific cases.

@Qix-

This comment has been minimized.

Qix- commented Apr 5, 2016

@glycerine such as on linux, writing to a .so produces an ar archive?... Haha

@sctb

This comment has been minimized.

Contributor

sctb commented Apr 24, 2016

Is this still an issue? Using go 1.6.1 under 10.11.4, I'm able to produce a dylib, codesign it, then use install_name_tool to change one of the referenced libraries:

$ go build -v -o dy.dylib -buildmode=c-shared dy.go

$ codesign --display dy.dylib 
dy.dylib: code object is not signed at all

$ codesign -s - dy.dylib 

$ codesign --display --verbose=4 dy.dylib 
Executable=/Users/sctb/Documents/go/src/scratch/dy.dylib
Identifier=dy-555549440baae12e4a2736199fdd79b6c9919bc0
Format=Mach-O thin (x86_64)
CodeDirectory v=20100 size=17564 flags=0x2(adhoc) hashes=542+4 location=embedded
Hash type=sha256 size=32
CandidateCDHash sha1=6dcc99af796f36291ca08bf4d6696db6a1c6fc1a
CandidateCDHash sha256=72f971707b73f738838dd586fb2bf905581723b2
Hash choices=sha1,sha256
CDHash=72f971707b73f738838dd586fb2bf905581723b2
Signature=adhoc
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements count=0 size=12

$ file dy.dylib 
dy.dylib: Mach-O 64-bit dynamically linked shared library x86_64

$ otool -L dy.dylib 
dy.dylib:
    dy.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

$ install_name_tool -change /usr/lib/libSystem.B.dylib /bar/system.dylib dy.dylib

$ otool -L dy.dylib
dy.dylib:
    dy.dylib (compatibility version 0.0.0, current version 0.0.0)
    /bar/system.dylib (compatibility version 1.0.0, current version 1226.10.1)

@lunixbochs

This comment has been minimized.

lunixbochs commented Jul 11, 2017

This doesn't seem to work under Go 1.8 on OS X 10.12 Sierra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment