On Apr 30, 2014 10:02 PM, "Alan Shreve" <al...@ngrok.com> wrote:
> I’ve automated this approach for anyone to use:
>
> https://github.com/inconshreveable/gonative
that's great! thanks for sharing.
> And it works! Almost!
>
> I’ve tested linux/darwin/windows on 386/amd64 (not freebsd or linux/arm yet) and everything seems to work great except . . .
>
> When I try to run linux_386 binaries on linux_amd64 machines. A simple hello world works, but if I try to use something that requires a native library like this:
>
> // test.go
> package main
>
> import (
> "fmt"
> "os/user"
> )
> func main() {
> u, err := user.Current()
> fmt.Printf("%v %v\n", u, err)
> }
>
> I get a really weird error:
>
> alan@inconshreveable:~$ ./test
> -bash: ./test: No such file or directory
>
> Any ideas on what could possibly be going on?
probably it can't find the elf interpreter.
what does "readelf -l test" output?
On Apr 30, 2014 11:26 PM, "Alan Shreve" <al...@inconshreveable.com> wrote:
> Elf file type is EXEC (Executable file)
> Entry point 0x8066a50
> There are 9 program headers, starting at offset 52
>
> Program Headers:
> Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
> PHDR 0x000034 0x08048034 0x08048034 0x00120 0x00120 R E 0x1000
> INTERP 0x000bed 0x08048bed 0x08048bed 0x00013 0x00013 R 0x1
> [Requesting program interpreter: /lib/ld-linux.so.2]
do you have this file?
if you have, then take a look at "ldd test".
the program header looks correct to me.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On May 1, 2014 12:17 AM, "Alan Shreve" <al...@inconshreveable.com> wrote:
>
> You’re right, I don’t have the 32-bit ELF interpreter. Thank you! I now realize this has nothing to do with the cross-compilation approach.
>
> This is stretching my knowledge, so my apologies if my questions don’t make sense. Why is it that binaries that are cross compiled to linux_386 *without Cgo* will run fine on a system without the ELF interpreter? What is necessary about linking with the natively-bulid 386 libraries that requires the ELF interpreter be present at runtime?
the elf interpreter is needed for dynamic linked executables.
when not using cgo, the program will be statically linked, so they don't need the elf interpreter.
On May 1, 2014 12:29 AM, "Alan Shreve" <al...@inconshreveable.com> wrote:
>
> Sorry, one last question. If I’m understanding correctly, the ELF interpreter only needs to be present for executables that are dynamically linked.
>
> ldd test says:
> “not a dynamic executable”
actually if you take a look at ldd's source code you will find that it's a script and just set some magic environment variable and then execute the program, essentially it's asking the elf interpreter to dump needed shared library.
so if you don't have the elf interpreter, the program will fail to execute and ldd mistake that as the program not being dynamically linked.
(that's the reason why i first ask you to verify you do have the elf interpreter and then use ldd)
PS: not all ldds work like this (because this is kinda a security hole to execute the program when you're only querying its dependencies, on certain systems, the ldd will actually read and parse the .dynamic section to get the needed shared libraries).
After some playing around, I'm pretty sure this does the business:$ GOROOT=$PWD/go PATH=$PWD/go/bin:$PATH gonative
$ GOROOT=$PWD/go PATH=$PWD/go/bin:$PATH gox -build-toolchain
$ GOROOT=$PWD/go PATH=$PWD/go/bin:$PATH gox
On Sunday, May 4, 2014 2:32:42 PM UTC-7, Robert wrote:Can you post an example of how to use gonative with gox to do an actual cross-compilation?
gonative builds the toolchain, but does not actually cross-compile...