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

Closed
albertjin opened this issue Sep 20, 2015 · 10 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@albertjin
Copy link

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
Copy link
Contributor

rakyll commented Sep 21, 2015

/cc @crawshaw

@rsc
Copy link
Contributor

rsc commented Nov 23, 2015

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

@glycerine
Copy link

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-
Copy link

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
Copy link

@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-
Copy link

Qix- commented Apr 5, 2016

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

@sctb
Copy link
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
Copy link

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

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 23, 2019
@bcmills bcmills added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 7, 2023
@bcmills bcmills changed the title cmd/go: dylib built as buildmode=c-shared causes 'overlapping segments' after codesign by Xcode on OS X cmd/link: dylib built as buildmode=c-shared causes 'overlapping segments' after codesign by Xcode on OS X Sep 7, 2023
@bcmills
Copy link
Contributor

bcmills commented Sep 7, 2023

The last update to this issue was six years ago. Is this still a problem?

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 7, 2023
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

10 participants