Bug 175605 - devel/binutils: please fix build binutils-2.23.1 in raspberry pi
Summary: devel/binutils: please fix build binutils-2.23.1 in raspberry pi
Status: Closed Overcome By Events
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-arm (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-26 14:10 UTC by guxianjie
Modified: 2014-09-27 09:26 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description guxianjie 2013-01-26 14:10:00 UTC
binutils-2.23.1 build failed in raspberry pi

Fix: 

add support armv6-portbld-freebsd10.0 in binutils' config files
example:
/usr/ports/devel/binutils/work/binutils-2.23.1/bfd/configure:  arm-*-freebsd* | arm-*-kfreebsd*-gnu | armv6-*-freebsd*)
How-To-Repeat: build binutils-2.23.1 in raspberry pi
Comment 1 Rene Ladan freebsd_committer freebsd_triage 2014-01-03 10:13:34 UTC
Responsible Changed
From-To: freebsd-arm->rene

Take
Comment 2 Rene Ladan freebsd_committer freebsd_triage 2014-01-05 12:41:22 UTC
[maintainer added]

Your fix works on my Raspberry Pi running 10.0-RC2 building binutils
2.24, but later on ld complains:

gmake[4]: Leaving directory
`/usr/ports/devel/binutils/work/binutils-2.24/gprof'
Configuring in ./ld
[...]
checking whether ANSI C string concatenation works... yes
checking size of void *... 4
*** ld does not support target armv6-portbld-freebsd10.0
*** see ld/configure.tgt for supported targets
gmake[3]: *** [configure-ld] Error 1

I patched ld/configure.tgt for this, but I'm not sure if it is correct
(should it be its own target?)

Patches are at http://people.freebsd.org/~rene/patches/devel__binutils.diff

René
Comment 3 Rene Ladan freebsd_committer freebsd_triage 2014-02-03 21:05:16 UTC
Responsible Changed
From-To: rene->freebsd-arm

Back to freebsd-arm, my patch produces a broken ld as can be seen in 
http://people.freebsd.org/~rene/patches/binutils-rpi-bug.txt
Comment 4 Anton Shterenlikht 2014-07-11 14:23:21 UTC
Another patchset:
http://lists.freebsd.org/pipermail/freebsd-arm/2014-May/008413.html

Just to keep this all in one place.

I'm building it right now.
Comment 5 Anton Shterenlikht 2014-07-11 15:46:13 UTC
executable segfaults:

$ cc -c z.c -Wall
$ /usr/local/bin/ld -o z /usr/lib/crt1.o /usr/lib/crti.o z.o -lc
$ file z
z: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for FreeBSD 10.0 (1000710), not stripped
$ ldd ./z
./z:
        libc.so.7 => /lib/libc.so.7 (0x2003c000)
$ ./z
Segmentation fault (core dumped)
$

$ pkg info -xo binu
binutils-2.24                  devel/binutils
$ uname -a
FreeBSD BOZO 10.0-STABLE FreeBSD 10.0-STABLE #0 r268038: Tue Jul  1 04:29:43 UTC 2014     root@grind.freebsd.org:/usr/obj/arm.armv6/usr/src/sys/RPI-B  arm
$
Comment 6 Anton Shterenlikht 2014-07-11 15:51:25 UTC
Forgot to say that this was with Andreas Tobler's patchset.
Also, it segfaults with the OS default ld too:

$ cat z.c
#include <stdio.h>
int main(int argc, char **argv)
{
        printf("mumu\n");
        return 0;
}
$ cc -c z.c -Wall
$ /usr/local/bin/ld -o z /usr/lib/crt1.o /usr/lib/crti.o z.o -lc
$ ldd z
z:
        libc.so.7 => /lib/libc.so.7 (0x2003c000)
$ file z
z: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for FreBSD 10.0 (1000710), not stripped
$ ./z
Segmentation fault (core dumped)
$ /usr/bin/ld -o z /usr/lib/crt1.o /usr/lib/crti.o z.o -lc
$ ldd z
z:
        libc.so.7 => /lib/libc.so.7 (0x2003c000)
$ file z
z: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for FreBSD 10.0 (1000710), not stripped
$ ./z
Segmentation fault (core dumped)
$
Comment 7 Andreas Tobler freebsd_committer freebsd_triage 2014-07-11 20:02:56 UTC
To get the right linker command do this:
(the -v is for verbose)

andreast@wandquad:~ % cc -o z  z.c -v
Using built-in specs.
Target: armv6-undermydesk-freebsd
Configured with: FreeBSD/armv6 system compiler
Thread model: posix
gcc version 4.2.1 20070831 patched [FreeBSD]
 /usr/libexec/cc1 -quiet -v -D_LONGLONG z.c -quiet -dumpbase z.c -auxbase z -version -o /tmp//ccMJ520s.s
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/gcc/4.2
 /usr/include
End of search list.
GNU C version 4.2.1 20070831 patched [FreeBSD] (armv6-undermydesk-freebsd)
	compiled by GNU C version 4.2.1 20070831 patched [FreeBSD].
GGC heuristics: --param ggc-min-expand=150 --param ggc-min-heapsize=130664
Compiler executable checksum: 20743f84b7aef1f094db166caa2fbdf7
 /usr/bin/as -mfpu=softvfp -meabi=4 -o /tmp//ccNNWzRe.o /tmp//ccMJ520s.s
 /usr/bin/ld --eh-frame-hdr -V -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -X -o z /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib -L/usr/lib /tmp//ccNNWzRe.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
GNU ld 2.17.50 [FreeBSD] 2007-07-03
  Supported emulations:
   armelf_fbsd


-->>

Then build only the z.o:

andreast@wandquad:~ % cc -c z.c -v
Using built-in specs.
Target: armv6-undermydesk-freebsd
Configured with: FreeBSD/armv6 system compiler
Thread model: posix
gcc version 4.2.1 20070831 patched [FreeBSD]
 /usr/libexec/cc1 -quiet -v -D_LONGLONG z.c -quiet -dumpbase z.c -auxbase z -version -o /tmp//ccoqB09j.s
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/gcc/4.2
 /usr/include
End of search list.
GNU C version 4.2.1 20070831 patched [FreeBSD] (armv6-undermydesk-freebsd)
	compiled by GNU C version 4.2.1 20070831 patched [FreeBSD].
GGC heuristics: --param ggc-min-expand=150 --param ggc-min-heapsize=130664
Compiler executable checksum: 20743f84b7aef1f094db166caa2fbdf7
 /usr/bin/as -mfpu=softvfp -meabi=4 -o z.o /tmp//ccoqB09j.s

-->

And last, link the z.o to z:

andreast@wandquad:~ % /build/gdb/testbin_armv6/bin/ld -V -Bstatic -X -o z /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbeginT.o -L/usr/lib z.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/lib/crtend.o /usr/lib/crtn.o
GNU ld (GNU Binutils) 2.24.51.20140706
  Supported emulations:
   armelf_fbsd
   armelfb_fbsd
   armelf
andreast@wandquad:~ % ./z 
mumu


Doesn't matter if static or dynamic, at least for me. And I'm on current.
Comment 8 Anton Shterenlikht 2014-07-12 15:24:12 UTC
Now I'm confused even further.
Your cc is GCC, whereas mine is clang:

$ cc -o z z.c -v
FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: armv6--freebsd10.0-gnueabi
Thread model: posix
Selected GCC installation:
 "/usr/bin/cc" -cc1 -triple armv6--freebsd10.0-gnueabi -S -disable-free -disable-ll
vm-verifier -main-file-name z.c -mrelocation-model static -mdisable-fp-elim -mconst
ructor-aliases -target-cpu arm1136jf-s -target-feature +soft-float -target-feature
+soft-float-abi -target-feature -neon -target-abi aapcs-linux -msoft-float -mfloat-
abi soft -v -resource-dir /usr/bin/../lib/clang/3.4.1 -fno-dwarf-directory-asm -fde
bug-compilation-dir /usr/home/mexas -ferror-limit 19 -fmessage-length 0 -mstackreal
ign -fno-signed-char -fobjc-runtime=gnustep -fdiagnostics-show-option -vectorize-sl
p -o /tmp/z-900faf.s -x c z.c
clang -cc1 version 3.4.1 based upon LLVM 3.4.1 default target armv6-gnueabi-freebsd
10.0
ignoring nonexistent directory "/usr/bin/../lib/clang/3.4.1/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/clang/3.4.1
 /usr/include
End of search list.
 "/usr/bin/as" -mfpu=softvfp -meabi=5 -o /tmp/z-669589.o /tmp/z-900faf.s
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=bot
h --enable-new-dtags -o z /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/us
r/lib /tmp/z-669589.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-neede
d -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o

Clearly I need to build binutils first, before I can build GCC, right?

Anyway, your other instructions helped.
I could compile z.c into z.o and link it like this:

/usr/local/bin/ld --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o z /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib z.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o

$ ./z
mumu
$

So I'd say your patchset should be committed.

Many thanks

Anton