ARM gentoo crossdev with uclibc: need OABI rather than EABI - gcc

Can anyone help with my ARM + GCC + UCLIBC linking issue with crossdev?
Also posted to Gentoo Forums here: http://forums.gentoo.org/viewtopic-t-925012.html
Recently, I was assigned to a project that has executables developed using an old GCC with OABI. As a point of reference, here's a header output from readelf of an executable that runs just fine on the system:
ELF Header:
Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: ARM
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x9464
Start of program headers: 52 (bytes into file)
Start of section headers: 540956 (bytes into file)
Flags: 0x202, has entry point, GNU EABI, software FP
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 6
Size of section headers: 40 (bytes)
Number of section headers: 35
Section header string table index: 32
I creaed a cross-compiler using crossdev and the latest gcc/binutils/linux-headers/etc. and with EABI.
$ crossdev arm-softfloat-linux-uclibceabi
I quite happily began to populate my local folder with executables using that cross compiler only to later try the executable on my hardware and find out that I ended up with a segmentation fault. I realized, only through quite a bit of googling, that I really needed to have the old, legacy ABI for uclibc: OABI. My previous cross compiler was from circa 2005.
As another point of reference, my executables with eabi were producing headers from readelf that look a bit like this:
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x8130
Start of program headers: 52 (bytes into file)
Start of section headers: 21284 (bytes into file)
Flags: 0x5000002, has entry point, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 40 (bytes)
Number of section headers: 21
Section header string table index: 18
While the Machine is the same, the segmentation fault doesn't provide a way to execute the binary on the target.
After googling more, I found that there may be a way to produce some code with the eabi compiler for the legacy system. I was quite happy when I ran this command:
$ arm-softfloat-linux-uclibceabi-gcc -mabi=apcs-gnu -static -c -o /mnt/arm_uclibc/tmp/test /mnt/arm/tmp/test.c && readelf -h /mnt/arm_uclibc/tmp/test
And I ended up with:
ELF Header:
Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: ARM
ABI Version: 0
Type: REL (Relocatable file)
Machine: ARM
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 248 (bytes into file)
Flags: 0x600, GNU EABI, software FP, VFP
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 12
Section header string table index: 9
At this point, I was getting antsy and I decided to try and create an executable with the -mabi=apcs-gnu,
arm-softfloat-linux-uclibceabi-gcc -mabi=apcs-gnu -static -o /mnt/arm_uclibc/tmp/test /mnt/arm/tmp/test.c
And I get a linker error:
/usr/libexec/gcc/arm-softfloat-linux-uclibceabi/ld: error: Source object /tmp/ccDq2f6R.o has EABI version 0, but target /mnt/arm_uclibc/tmp/test has EABI version 5
/usr/libexec/gcc/arm-softfloat-linux-uclibceabi/ld: failed to merge target specific data of file /tmp/ccDq2f6R.o
collect2: ld returned 1 exit status
QUESTION: This leads me to believe that my EABI is incorrect and I need OABI. Is that right?
I believed that it was the case, so I began to look into uclibc through crossdev:
$ crossdev arm-softfloat-linux-uclibc -P -v
I am happy to report that the files that DO get compiled into some sort of object binary have the right elf header. So I think this is what I want.
But this dies during compilation for uclibc as follows:
make[1]: `lib/ld-uClibc.so' is up to date.
LD libuClibc-0.9.33.2.so
libc/libc_so.a(_fpmaxtostr.os): In function `_fpmaxtostr':
_fpmaxtostr.c:(.text+0xbc): undefined reference to `__nedf2'
_fpmaxtostr.c:(.text+0xe0): undefined reference to `__eqdf2'
_fpmaxtostr.c:(.text+0xfc): undefined reference to `__divdf3'
_fpmaxtostr.c:(.text+0x108): undefined reference to `__ltdf2'
_fpmaxtostr.c:(.text+0x17c): undefined reference to `__muldf3'
_fpmaxtostr.c:(.text+0x348): undefined reference to `__gedf2'
_fpmaxtostr.c:(.text+0x40c): undefined reference to `__fixunsdfsi'
libc/libc_so.a(__psfs_do_numeric.os): In function `__psfs_do_numeric':
__psfs_do_numeric.c:(.text+0x534): undefined reference to `__truncdfsf2'
libc/libc_so.a(close.oS):(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
collect2: ld returned 1 exit status
make: *** [lib/libc.so] Error 1
If I have broken the error down properly, I believe that
1) The arm Makefile.arch is not properly building __aeabi_unwind_cpp_pr0 because the file is only built when EABI is set:
$ find . -name 'Makefile.arch' -exec grep -i -H -n 'pr1' "{}" \;
./uclibc-0.9.33.2/work/uClibc-0.9.33.2/libc/sysdeps/linux/arm/Makefile.arch:45: $(ARCH_OUT)/aeabi_sighandlers.os $(ARCH_OUT)/aeabi_unwind_cpp_pr1.o
$ find . -name 'aeabi_unwind_cpp_pr1.c*'
./uclibc-0.9.33.2/work/uClibc-0.9.33.2/libc/sysdeps/linux/arm/aeabi_unwind_cpp_pr1.c
$ cat ./uclibc-0.9.33.2/work/uClibc-0.9.33.2/libc/sysdeps/linux/arm/aeabi_unwind_cpp_pr1.c
#include <stdlib.h>
attribute_hidden void __aeabi_unwind_cpp_pr0 (void);
attribute_hidden void __aeabi_unwind_cpp_pr0 (void)
{
}
attribute_hidden void __aeabi_unwind_cpp_pr1 (void);
attribute_hidden void __aeabi_unwind_cpp_pr1 (void)
{
}
attribute_hidden void __aeabi_unwind_cpp_pr2 (void);
attribute_hidden void __aeabi_unwind_cpp_pr2 (void)
{
}
I believe the fix for this error is:
--- Makefile.arch.old 2012-05-28 00:43:52.918708833 -0500
+++ Makefile.arch.new 2012-05-28 00:44:30.658708443 -0500
## -42,5 +42,6 ##
libc-static-y += $(ARCH_OUT)/aeabi_lcsts.o $(ARCH_OUT)/aeabi_math.o \
$(ARCH_OUT)/aeabi_sighandlers.o
libc-nonshared-y += $(ARCH_OUT)/aeabi_lcsts.os $(ARCH_OUT)/aeabi_math.os \
- $(ARCH_OUT)/aeabi_sighandlers.os $(ARCH_OUT)/aeabi_unwind_cpp_pr1.o
+ $(ARCH_OUT)/aeabi_sighandlers.os
endif
+libc-nonshared-y += $(ARCH_OUT)/aeabi_unwind_cpp_pr1.o
2) The soft-float in gcc is not properly being included either by the linker. I can't really tell why at this point.
$ find . -name '*.c' -exec grep -i -H -n nedf2 "{}" \;
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/mips/mips.c:11123: set_optab_libfunc (ne_optab, DFmode, "__mips16_nedf2");
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/eqdf2.c:51:strong_alias(__eqdf2, __nedf2);
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/testsuite/gcc.c-torture/execute/gofast.c:32:int nedf2 (double a, double b) { return a != b; }
./gcc-4.5.3-r2/work/gcc-4.5.3/libgcc/config/rx/rx-abi-functions.c:41:int _COM_CMPNEd (double a, double b) { return __nedf2 (a, b) != 0; }
$ ls ./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/
README double.h extendsftf2.c fixsfti.c fixunssfdi.c floatdisf.c floattitf.c floatuntidf.c lesf2.c negtf2.c single.h trunctfdf2.c
adddf3.c eqdf2.c extendxftf2.c fixtfdi.c fixunssfsi.c floatditf.c floatundidf.c floatuntisf.c letf2.c op-1.h soft-fp.h trunctfsf2.c
addsf3.c eqsf2.c fixdfdi.c fixtfsi.c fixunssfti.c floatsidf.c floatundisf.c floatuntitf.c muldf3.c op-2.h subdf3.c trunctfxf2.c
addtf3.c eqtf2.c fixdfsi.c fixtfti.c fixunstfdi.c floatsisf.c floatunditf.c gedf2.c mulsf3.c op-4.h subsf3.c unorddf2.c
divdf3.c extenddftf2.c fixdfti.c fixunsdfdi.c fixunstfsi.c floatsitf.c floatunsidf.c gesf2.c multf3.c op-8.h subtf3.c unordsf2.c
divsf3.c extended.h fixsfdi.c fixunsdfsi.c fixunstfti.c floattidf.c floatunsisf.c getf2.c negdf2.c op-common.h t-softfp unordtf2.c
divtf3.c extendsfdf2.c fixsfsi.c fixunsdfti.c floatdidf.c floattisf.c floatunsitf.c ledf2.c negsf2.c quad.h truncdfsf2.c
$ grep -i -H -n nedf2 ./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/*
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/eqdf2.c:51:strong_alias(__eqdf2, __nedf2);
$ grep -i -H -n eqdf2 ./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/*
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/eqdf2.c:35:CMPtype __eqdf2(DFtype a, DFtype b)
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/eqdf2.c:51:strong_alias(__eqdf2, __nedf2);
$ grep -i -H -n divdf3 ./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/*
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/divdf3.c:35:DFtype __divdf3(DFtype a, DFtype b)
$ grep -i -H -n ltdf2 ./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/*
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/ledf2.c:51:strong_alias(__ledf2, __ltdf2);
$ grep -i -H -n muldf3 ./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/*
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/muldf3.c:35:DFtype __muldf3(DFtype a, DFtype b)
$ grep -i -H -n gedf2 ./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/*
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/gedf2.c:35:CMPtype __gedf2(DFtype a, DFtype b)
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/gedf2.c:51:strong_alias(__gedf2, __gtdf2);
$ grep -i -H -n fixunsdfsi ./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/*
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/fixunsdfsi.c:35:USItype __fixunsdfsi(DFtype a)
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/t-softfp:71:softfp_func_list := $(filter-out floatdidf floatdisf fixunsdfsi fixunssfsi \
$ grep -i -H -n truncdfsf2 ./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/*
./gcc-4.5.3-r2/work/gcc-4.5.3/gcc/config/soft-fp/truncdfsf2.c:36:SFtype __truncdfsf2(DFtype a)
So I tried to force GCC to build for a soft-float and get that linked later within uclibc's build:
$ UCLIBC_CPU=ARM926T ACCEPT_KEYWORDS="arm" CPU_CFLAGS="-marm -march=armv5te -mtune=arm926ej-s -mabi=apcs-gnu -mno-thumb" EXTRA_FLAGS="-msoft-float -mfloat-abi=soft" UCLIBC_EXTRA_CFLAGS="${CPU_CFLAGS} ${EXTRA_CFLAGS}" STAGE1_CFLAGS="${EXTRA_CFLAGS}" CFLAGS="${EXTRA_CFLAGS}" crossdev -A arm -t arm-softfloat-linux-uclibc -P -v
And then I checked to see if -msoft-float and -mfloat-abi=soft were used within any log for compiling.
$ find . -name '*.log' -exec grep -i -H -n msoft-float "{}" \;
<nothing>
$ find . -name '*.log'
./work/build/arm-softfloat-linux-uclibc/libgcc/config.log
./work/build/libcpp/config.log
./work/build/gcc/config.log
./work/build/fixincludes/config.log
./work/build/intl/config.log
./work/build/build-x86_64-pc-linux-gnu/libiberty/config.log
./work/build/build-x86_64-pc-linux-gnu/fixincludes/config.log
./work/build/libdecnumber/config.log
./work/build/libiberty/config.log
./work/build/config.log
./work/gcc-4.5.3/contrib/reghunt/examples/29478.log
./work/gcc-4.5.3/contrib/reghunt/examples/29906a.log
./work/gcc-4.5.3/contrib/reghunt/examples/29906b.log
./work/gcc-4.5.3/contrib/reghunt/examples/28970.log
./work/gcc-4.5.3/contrib/reghunt/examples/29106.log
./work/gcc-4.5.3/contrib/reghunt/examples/30643.log
./temp/elibtool.log
./temp/epatch_user.log
./temp/epatch.log
./temp/eclass-debug.log
./temp/build.log
But I do note that --with-float=soft is set within the config.log, so that makes me believe that the float should have been generated.
And I note the -D__GCC_FLOAT_NOT_NEEDED in the compilation options for gcc.
I ran a regression on GCC to see where the break occurred.
gcc 4.x does not work with uclibc.
-- starting with 4.4.4-r2, uclibc has a linking failure with gcc
-- prior to 4.4.4, gcc does not appear to
gcc-3.4.6-r2 does work provided that USE=-nptl is used
For reference I ran:
binutils: 2.22-r1
Linux Header: 3.3, 3.4
uclibc: 0.9.33.2
gcc: 3.2.3-r4, 3.3.6-r1, 3.4.6-r2, 4.1.4-r1, 4.3.3-r2, 4.4.2, 4.4.4-r2, 4.4.5, 4.4.6-r1, 4.4.7, 4.5.3-r2, 4.6.0, 4.6.1-r1, 4.6.2, 4.6.3

I ended up moving to gcc-4.7.0. The final build is:
binutils-2.22-r1
gcc-4.7.0
linux-headers-3.4
uclibc-0.9.33.2
My working crossdev arm-softfloat-linux-uclibc compiler command looks like this:
#!/usr/bin/env sh
CHOST=${CHOST-arm-softfloat-linux-uclibc}
USE="-nptl" \
crossdev -t ${CHOST} \
-A arm -P "--digest" \
--g 4.7.0 --genv 'EXTRA_ECONF="--enable-obsolete --with-cpu=arm926ej-s \
--without-system-libunwind --with-mode=arm \
--with-abi=apcs-gnu --with-float-abi=soft"' \
--lenv 'UCLIBC_CPU="ARM926T" \
UCLIBC_EXTRA_CFLAGS="-marm -mcpu=arm926ej-s"'
The options above might not all be needed, but as a note, the next major version of gcc is going to obsolete uclibc's OABI unless they end up with a developer that's willing to keep it updated. There hasn't been one in at least two years.
Also, I do not have nptl enabled with gcc. I think it is possible to do a crossdev build stage 3 without nptl enabled and then do the final gcc with nptl, but I have not done any testing with the binaries to prove that this actually inserts nptl.
Unfortunately, gcc and uclibc do not play nice together right out of the box. I also realized I needed some patches to fix the errors I found.
To make this easier on myself, I also ended up creating a patches folder so I didn't have to create an entirely new overlay with ebuilds. During the execution of emerge, this let me add patches on the fly. For the most part, this will work with most packages. I'm still working with Python to make that a smooth compile.
Creating the patches folder:
$ mkdir /etc/portage/patches
Updating portage bashrc:
File: /etc/portage/bashrc
#!/usr/bin/env sh
[[ $(basename $(readlink -f $PORTAGE_CONFIGROOT/etc/make.profile)) == "embedded" ]] && . ${PORTDIR}/profiles/base/profile.bashrc
post_src_install() {
[[ -d ${D} ]] || return 0
[[ ${E_MACHINE} == "" ]] && return 0
cmdline=""
for EM in $E_MACHINE; do
cmdline+=" -e ^${EM}[[:space:]]";
done
output="$( cd ${D} && scanelf -RmyBF%a . | grep -v ${cmdline} )"
[[ $output != "" ]] && { echo; echo "* Wrong EM_TYPE. Expected ${E_MACHINE}"; echo -e "${output}"; echo; exit 1; }
}
# We don't run this on the assumption that when you're
# emerging binary packages, it's into a runtime ROOT
# rather than build development ROOT. The former doesn't
# want hacking while the latter does.
if [[ $EBUILD_PHASE == "postinst" ]]; then
[[ $SYSROOT == $ROOT ]] && cross-fix-root ${CHOST}
fi
eecho() {
#[ "$NOCOLOR" = "false" ] && echo -ne '\e[1;34m>\e[1;36m>\e[1;35m>\e[0m ' || echo -n ">>> "
echo -ne '\e[1;34m>\e[1;36m>\e[1;35m>\e[0m ' || echo -n ">>> "
echo "$*"
}
run_autopatch () {
#echo ">>> --------------------------------------------------------------------"
#echo ">>>"
#echo ">>> Phase: $EBUILD_PHASE"
#echo ">>>"
#echo ">>> --------------------------------------------------------------------"
patchit="no"
if [[ $EBUILD_PHASE == prepare ]]; then
patchit="yes"
elif [[ $EBUILD_PHASE == configure ]]; then
patchit="yes"
elif [[ $EBUILD_PHASE == compile ]]; then
patchit="yes"
fi
if [[ $patchit != "no" ]]; then
# echo ">>> Patching"
[[ ! -d "$PATCH_OVERLAY" ]] && echo "PATCH_OVERLAY is not a directory: $PATCH_OVERLAY" && return 0;
[[ ! -r ${ROOT}etc/portage/bashrc.autopatch ]] && echo "Couldn't read autopatch script: ${ROOT}/etc/portage/bashrc.autopatch" && return 0;
source ${ROOT}etc/portage/bashrc.autopatch
fi
}
if [[ " ${FEATURES} " == *" autopatch "* ]] || [[ $AUTOPATCH="yes" ]]; then
run_autopatch
fi
Also need to create bashrc.autopatch.
File: /etc/portage/bashrc.autopatch
#!/usr/bin/env sh
# <solar#gentoo> 2005
# Distributed under the terms of the GNU General Public License v2
# $Header: $
# updated by brian bruggeman
autopatch() {
local diff level p patches patched
[[ ! -d "$PATCH_OVERLAY" ]] && return 0
patches=$(ls -1 ${PATCH_OVERLAY}/${CATEGORY}/${PN}/${PN}-*.{patch,diff} 2>/dev/null)
[[ $patches == "" ]] && echo "No patches found: ${PATCH_OVERLAY}/${CATEGORY}/${PN}/${PN}-*.patch" && return 0
if [[ -d $S ]] && [[ -e $S ]]; then
cd $S
else
echo ">>> Couldn't cd to $S"
fi
echo -e ' \e[0;36m*\e[0m '"Applying Autopatches from $PATCH_OVERLAY ..."
for p in ${patches}; do
p=$(basename $p)
diff=${PATCH_OVERLAY}/${CATEGORY}/${PN}/${p}
if [[ -e $diff ]] && [ ! -e ${S}/.${p} ]; then
patched=0
for level in 0 1 2 3 4; do
if [[ $patched == 0 ]]; then
patch -g0 --dry -p${level} >/dev/null < $diff
if [ $? = 0 ]; then
echo -e ' \e[0;36m*\e[0m '" (-p${level}) ${p}"
patch -g0 -p${level} < $diff > /dev/null && patched=1
touch $S/.${p}
fi
fi
done
[[ $patched != 1 ]] && echo "!!! FAILED auto patching $p"
else
[[ ! -e $diff ]] && echo "!!! $diff does not exist, unable to auto patch"
fi
done
echo -e ' \e[0;36m*\e[0m '"Done with patching auto patches ..."
cd $OLDPWD
}
PATH=$PATH:/usr/sbin:/usr/bin:/bin:/sbin
autopatch
Creating a patch for gcc:
$ cd /etc/portage/packages
$ mkdir -p cross-arm-softfloat-linux-uclibc/gcc-4.7.0
$ cd cross-arm-softfloat-linux-uclibc/gcc-4.7.0
$ touch gcc-4.7.0-softfloat.patch
File: /etc/portage/packages/cross-arm-softfloat-linux-uclibc/gcc-4.7.0/gcc-4.7.0-softfloat.patch
Index: gcc/config/arm/linux-elf.h
===================================================================
--- gcc/config/arm/linux-elf.h 2011-04-11 13:46:05.000000000 -0500
+++ gcc/config/arm/linux-elf.h.new 2012-05-31 14:24:14.465545128 -0500
## -48,7 +48,7 ##
#undef MULTILIB_DEFAULTS
#define MULTILIB_DEFAULTS \
- { "marm", "mlittle-endian", "mfloat-abi=hard", "mno-thumb-interwork" }
+ { "marm", "mlittle-endian", "mfloat-abi=soft", "mno-thumb-interwork" }
/* Now we define the strings used to build the spec file. */
#undef LIB_SPEC
## -57,7 +57,7 ##
%{shared:-lc} \
%{!shared:%{profile:-lc_p}%{!profile:-lc}}"
-#define LIBGCC_SPEC "%{mfloat-abi=soft*:-lfloat} -lgcc"
+#define LIBGCC_SPEC "-lgcc"
#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
Index: libgcc/config/arm/t-linux
===================================================================
--- ./libgcc/config/arm/t-linux 2011-11-02 10:23:48.000000000 -0500
+++ ./libgcc/config/arm/t-linux.new 2012-05-31 14:29:57.715541608 -0500
## -1,6 +1,10 ##
LIB1ASMSRC = arm/lib1funcs.S
LIB1ASMFUNCS = _udivsi3 _divsi3 _umodsi3 _modsi3 _dvmd_lnx _clzsi2 _clzdi2 \
- _arm_addsubdf3 _arm_addsubsf3
+ _arm_addsubdf3 _arm_addsubsf3 \
+ _arm_negdf2 _arm_muldivdf3 _arm_cmpdf2 _arm_unorddf2 \
+ _arm_fixdfsi _arm_fixunsdfsi _arm_truncdfsf2 \
+ _arm_negsf2 _arm_muldivsf3 _arm_cmpsf2 _arm_unordsf2 \
+ _arm_fixsfsi _arm_fixunssfsi
# Just for these, we omit the frame pointer since it makes such a big
# difference.
Creating a patch for uclibc:
$ cd /etc/portage/packages
$ mkdir -p cross-arm-softfloat-linux-uclibc/uclibc
$ cd cross-arm-softfloat-linux-uclibc/uclibc
$ touch uclibc-0.9.33.2-unwind-fixes.patch
File: /etc/portage/packages/cross-arm-softfloat-linux-uclibc/uclibc/uclibc-0.9.33.2-unwind-fixes.patch
Index: libc/sysdeps/linux/arm/Makefile.arch
===================================================================
--- ./libc/sysdeps/linux/arm/Makefile.arch 2012-05-15 02:20:09.000000000 -0500
+++ ./libc/sysdeps/linux/arm/Makefile.arch.new 2012-05-31 00:43:11.176050458 -0500
## -42,5 +42,6 ##
libc-static-y += $(ARCH_OUT)/aeabi_lcsts.o $(ARCH_OUT)/aeabi_math.o \
$(ARCH_OUT)/aeabi_sighandlers.o
libc-nonshared-y += $(ARCH_OUT)/aeabi_lcsts.os $(ARCH_OUT)/aeabi_math.os \
- $(ARCH_OUT)/aeabi_sighandlers.os $(ARCH_OUT)/aeabi_unwind_cpp_pr1.o
+ $(ARCH_OUT)/aeabi_sighandlers.os
endif
+libc-nonshared-y += $(ARCH_OUT)/aeabi_unwind_cpp_pr1.o
Index: libc/sysdeps/linux/arm/unwind.h
===================================================================
--- ./libc/sysdeps/linux/arm/unwind.h 2012-05-31 00:57:39.356041552 -0500
+++ ./libc/sysdeps/linux/arm/unwind.h.new 2012-05-31 01:04:55.436037080 -0500
## -34,6 +34,8 ##
#define __ARM_EABI_UNWINDER__ 1
+#include <stdlib.h>
+
#ifdef __cplusplus
extern "C" {
#endif
## -211,7 +213,7 ##
_Unwind_Control_Block *, struct _Unwind_Context *, void *);
_Unwind_Reason_Code _Unwind_ForcedUnwind (_Unwind_Control_Block *,
_Unwind_Stop_Fn, void *);
- _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
+ extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
void _Unwind_Complete(_Unwind_Control_Block *ucbp);
void _Unwind_DeleteException (_Unwind_Exception *);

Related

make on ubuntu vs Mingw32-make on windows -- unable to execute ! and other commands

The following structure works fine on a native ubuntu machine:
Makefile
Makefile-Debug
Makefile-impl
I call make with make CONF=Debug
Contents of Makefile are:
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
build: .build-post
.build-pre:
.build-post: .build-impl
clean: .clean-post
.clean-pre:
.clean-post: .clean-impl
clobber: .clobber-post
.clobber-pre:
.clobber-post: .clobber-impl
all: .all-post
.all-pre:
.all-post: .all-impl
build-tests: .build-tests-post
.build-tests-pre:
.build-tests-post: .build-tests-impl
test: .test-post
.test-pre: build-tests
.test-post: .test-impl
help: .help-post
.help-pre:
.help-post: .help-impl
include Makefile-impl.mk <<----this file gets executed
include Makefile-variables.mk
Now, Makefile-impl.mk has the following line where it is checked whether the makefile corresponding to the Debug configuration -- Makefile-Debug -- actually exists:
.validate-impl:
#if [ ! -f Makefile-${CONF}.mk ]; \ <<------ this line produces an error in MinGW
then \
echo ""; \
echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \
echo "See 'make help' for details."; \
echo "Current directory: " `pwd`; \
echo ""; \
fi
#if [ ! -f Makefile-${CONF}.mk ]; \
then \
exit 1; \
fi
The above works perfectly fine on the native ubuntu machine.
When mingw32-make.exe processes the above on a windows machine, I obtain an error:
! was unexpected at this time.
mingw32-make: *** [Makefile-impl.mk:90: .validate-impl] Error 255
Is there any workaround for this? I also obtain other errors, such as for -n on the following different line in Makefile-impl.mk
#if [ -n "${MAKE_VERSION}" ]; then \
Here the error is:
-n was unexpected at this time.
mingw32-make: *** [Makefile-impl.mk:78: .depcheck-impl] Error 255

Trying to add Zsh shell (with Oh My Zsh!) to new Windows Terminal, what's the right way?

Using MSYS2 and following Zsh on Windows via MSYS2 guide I installed Zsh shell on my Windows 10 Pro workstation. I installed Oh My Zsh! too via curl and powerlevel10k theme. Now I'd like to use this shell with new Windows Terminal (Preview) so in profiles.json I added this configuration:
{
"guid": "{00000000-0000-0000-bb55-000000000003}",
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"commandline" : "\"C:\\msys64\\usr\\bin\\zsh.exe\" -i -l",
"historySize" : 9001,
"icon" : "C:\\msys64\\mingw64\\share\\git\\git-for-windows.ico",
"name" : "Oh my Zsh!",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
}
this works roughly but the prompt is not shown correctly and, every time I start the terminal, the following error is shown:
[ERROR]: gitstatus failed to initialize.
Your Git prompt may disappear or become slow.
Run the following command to retry with extra diagnostics:
GITSTATUS_LOG_LEVEL=DEBUG gitstatus_start POWERLEVEL9K
If this command produces no output, add the following parameter to ~/.zshrc:
GITSTATUS_LOG_LEVEL=DEBUG
With this parameter gitstatus will print additional information on error.
If i run GITSTATUS_LOG_LEVEL=DEBUG gitstatus_start POWERLEVEL9K, I get:
[ERROR]: gitstatus failed to initialize.
Your Git prompt may disappear or become slow.
The content of /tmp/gitstatus.197609.3944.1583052616.xtrace.log (gitstatus_start xtrace):
+(anon):7> (( ! _GITSTATUS_STATE_POWERLEVEL9K ))
+(anon):8> [[ -r /proc/version && 'MSYS_NT-10.0-19041 version 3.0.7-338.x86_64 (Alexx#WARLOCK) (gcc version 9.1.0 (GCC) ) 2019-07-11 10:58 UTC' == *Microsoft* ]]
+(anon):11> print -rn
+(anon):12> zsystem flock -f lock_fd /tmp/gitstatus.197609.3944.1583052616.lock
+(anon):13> [[ 14 == <1-> ]]
+(anon):15> typeset -gi '_GITSTATUS_LOCK_FD_POWERLEVEL9K=lock_fd'
+(anon):18> '(anon)' /proc/self/fd/16
+(anon):1> typeset -gi 'GITSTATUS_DAEMON_PID_POWERLEVEL9K=4011'
+(anon):2> sysopen -r -o cloexec -u resp_fd -- /proc/self/fd/16
+(anon):3> [[ 18 == <1-> ]]
+(anon):4> typeset -gi '_GITSTATUS_RESP_FD_POWERLEVEL9K=resp_fd'
+(anon):107> typeset -gi '_GITSTATUS_STATE_POWERLEVEL9K=1'
+(anon):110> (( ! async ))
+(anon):111> (( _GITSTATUS_CLIENT_PID_POWERLEVEL9K == sysparams[pid] ))
+(anon):113> local pgid
+(anon):114> (( 0 < 20 ))
+(anon):115> [[ -t 18 ]]
+(anon):116> sysread -s 20 -t 5.0000000000 -i 18 'pgid[$#pgid+1]'
+(anon):116> return
^ this command failed (5)
The content of /tmp/gitstatus.197609.3944.1583052616.daemon.log (gitstatus daemon log):
+(anon):20> local pgid=4011
+(anon):21> [[ 4011 == <1-> ]]
+(anon):91> (( lock_fd == -1 ))
+(anon):25> trap '' PIPE
+(anon):27> [[ -z '' ]]
+(anon):28> local kernel
+(anon):94> zsystem flock -- /tmp/gitstatus.197609.3944.1583052616.lock
+(anon):29> kernel=+(anon):29> uname -s
+(anon):29> kernel=msys_nt-10.0-19041
+(anon):30> [[ -n msys_nt-10.0-19041 ]]
+(anon):33> [[ '' == /* ]]
+(anon):35> (( 0 ))
+(anon):37> [[ -n '' ]]
+(anon):40> local os
+(anon):41> case msys_nt-10.0-19041 (linux)
+(anon):41> case msys_nt-10.0-19041 (cygwin_nt-*)
+(anon):41> case msys_nt-10.0-19041 (mingw | msys)
+(anon):41> case msys_nt-10.0-19041 (*)
+(anon):49> os=msys_nt-10.0-19041
+(anon):51> local arch
+(anon):52> arch=+(anon):52> uname -m
+(anon):52> arch=x86_64
+(anon):53> [[ -n x86_64 ]]
+(anon):54> local daemons=( /c/Users/icolumbro/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/usrbin/gitstatusd-msys_nt-10.0-19041-x86_64 /c/Users/icolumbro/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/usrbin/gitstatusd-msys_nt-10.0-19041-x86_64-static /c/Users/icolumbro/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/bin/gitstatusd-msys_nt-10.0-19041-x86_64 /c/Users/icolumbro/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/bin/gitstatusd-msys_nt-10.0-19041-x86_64-static )
+(anon):57> daemons=( )
+(anon):58> daemons=( )
+(anon):59> (( 0 ))
+(anon):59> return
+(anon):86> local -i ret=1
+(anon):87> kill -- -4011
Your system information:
zsh: 5.8
uname -a: MSYS_NT-10.0-19041 z800 3.0.7-338.x86_64 2019-07-11 10:58 UTC x86_64 Msys
If you need help, open an issue and attach this whole error message to it:
https://github.com/romkatv/gitstatus/issues/new
Can you help me to configure Windows Terminal to use Oh My Zsh! with powerlevel10k theme correctly, please?
I have Zsh installed on Windows natively based on MSYS2 too. It's not on the Virtual Machine guest nor the Windows Subsystem for Linux. So you can have the best performance with the Linux shell on Windows, native compilers for Windows, tight engagement with the OS, and many other benefits.
The steps of setting up the environment are documented on the README of my dotfiles. I'm not going to copy the steps here as the paragraph is long and I don't want to go through it again just for converting the format for Stack Overflow. Please follow the section prerequisite for Windows and installation. I'm sure you can set it up properly on your machine as I built this document on Windows 10 and just tested it on a fresh installed Windows 11.

OSX: dtrace printf(), write_nocancel() output base on dtruss script

I need to see my program's printf output in sync with the dtrace output.
I like to build my own version of dtrace command that produce the equivalent output of the "sudo dtruss -t write_nocancel ls" command.
This is the "correct dtruss command/output":
sudo dtruss -t write_nocancel ls
Chap1 Chap10 Chap11 Chap12 Chap2 Chap3 Chap4 Chap5 Chap6 Chap7 Chap8 Chap9 README
SYSCALL(args) = return
write_nocancel(0x1, "Chap1\tChap10\tChap11\tChap12\tChap2\tChap3\tChap4\tChap5\tChap6\tChap7\tChap8\tChap9\tREADME\n\0", 0x52) = 82 0
Base on looking at the dtruss script source code, I tried this dtrace command, but it failed.
sudo dtrace -q \
-n '*:*:write_nocancel:entry {self->arg0=arg0; self->arg1 =arg1; \
self->arg2 =arg2; self->code=0; } ' \
-n '*:*:write_nocancel:return { \
printf("return %s(0x%X, \"%S\", 0x%X) = %d %d", \
probefunc,self->arg0, arg0 == -1 ? "" : stringof(copyin(self->arg1,arg0)),self->arg2,(int)arg0, \
(int)errno); }' \
-c ls 2>&1
Chap1
Chap10
Chap11
Chap12
Chap2
Chap3
Chap4
Chap5
Chap6
Chap7
Chap8
Chap9
README
dtrace: error on enabled probe ID 3 (ID 209288: fbt:mach_kernel:write_nocancel:return): invalid address (0xffffff80218dfc40) in action #3 at DIF offset 92
dtrace: error on enabled probe ID 4 (ID 958: syscall::write_nocancel:return): invalid address (0xffffff80218dfc40) in action #3 at DIF offset 92
dtrace: error on enabled probe ID 3 (ID 209288: fbt:mach_kernel:write_nocancel:return): invalid address (0xffffff801a7c0010) in action #3 at DIF offset 92
Any dtrace experts out there might have a clue on how to fixe this?
Find the answer: (The issue of two -n options).
sudo dtrace -q -n \
'syscall::write_nocancel:entry{self->start = 1; \
self->vstart = 1; self->arg0 = arg0; \
self->arg1 = arg1; self->arg2 = arg2;} \
*:*:write_nocancel:return /self->start/ \
{ printf("return %s(0x%X, \"%S\", 0x%X) = %d %d" \
,probefunc,self->arg0, \
arg0 == -1 ? "" : stringof(copyin(self->arg1,arg0)),\
self->arg2,(int)arg0, (int)errno); }' \
-c ls 2>&1

YML parsing error

I'm trying to compile the bitcoin client for windows from ubutno but everytime I try to build it I keep getting this error:
/usr/lib/ruby/1.9.1/psych.rb:207:in `parse': (../bitcoin/contrib/gitian-descriptors/boost-win32.yml): could not find expected ':' while scanning a simple key at line 21 column 1 (Psych::SyntaxError)
I have investigated a bit about it and found that this is normally caused by some typo in the YML file. However I hardly know anything about ruby and was hoping that some of you guys could help me solve this problem.
My yml file is:
---
name: "boost"
suites:
- "lucid"
architectures:
- "i386"
packages:
- "mingw32"
- "faketime"
- "zip"
reference_datetime: "2011-01-30 00:00:00"
remotes: []
files:
- "boost_1_49_0.tar.bz2"
script: |
TMPDIR="$HOME/tmpdir"
mkdir -p $TMPDIR/bin/$GBUILD_BITS $TMPDIR/include
tar xjf boost_1_49_0.tar.bz2
cd boost_1_49_0
echo "--- tmp_dir_helpers.orig.hpp 2012-06-10 01:39:25.403268210 +0200
+++ tmp_dir_helpers.hpp 2012-06-10 01:41:14.653823479 +0200
## -19,9 +19,9 ##
#include <string>
#if defined(BOOST_INTERPROCESS_WINDOWS)
- //#define BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME
- //#define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
- //#include <boost/interprocess/detail/win32_api.hpp>
+ #define BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME
+ #define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
+ #include <boost/interprocess/detail/win32_api.hpp>
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
//#include <sys/sysctl.h>
//#if defined(CTL_KERN) && defined (KERN_BOOTTIME)" > useboottime.patch
patch boost/interprocess/detail/tmp_dir_helpers.hpp useboottime.patch
echo "using gcc : 4.4 : i586-mingw32msvc-g++
:
<rc>i586-mingw32msvc-windres
<archiver>i586-mingw32msvc-ar
<cxxflags>-frandom-seed=boost1
;" > user-config.jam
./bootstrap.sh --without-icu
./bjam toolset=gcc target-os=windows threadapi=win32 threading=multi variant=release link=static --user-config=user-config.jam --without-mpi --without-python -sNO_BZIP2=1 -sNO_ZLIB=1 --layout=tagged --build-type=complete $MAKEOPTS stage
for lib in chrono date_time exception filesystem graph iostreams math_c99f math_c99l math_c99 math_tr1f math_tr1l math_tr1 prg_exec_monitor program_options random regex serialization signals system test_exec_monitor thread_win32 unit_test_framework wave wserialization; do
mkdir $lib
(cd $lib ; ar xf ../stage/lib/libboost_${lib}-mt-s.a)
mv $lib $TMPDIR/bin/$GBUILD_BITS
done
cp -a boost $TMPDIR/include
cd $TMPDIR
export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
export FAKETIME=$REFERENCE_DATETIME
zip -r boost-win32-1.49.0-gitian2.zip *
cp boost-win32-1.49.0-gitian2.zip $OUTDIR
Thank you in advance and sorry if I'm asking to much :)
Edit:
by the way, I'm using Ruby 1.9.1 and my machine is running Ubuntu 13.0

How to batch files in shell script?

I would like to build a shell script to automatically archive object files into a static library, and copy all the headers and .a file to desired directory.
However, as the number of obj files grows, the following mess gets worse:
8 CWD=$(pwd)
9
10 FILE1="SDL_Logger.o"
11 HEADER1="SDL_Logger.h"
12 FILE2="SDL_Initializer.o"
13 HEADER2="SDL_Logger.h"
14 ARC="libsdlhelper.a"
15
16 INCLUDE=~/include
17 LIB=~/lib
18
19 if [ ! -f $FILE1 ];
20 then
21 echo " error: file $FILE1 does not exist. Abort."
22 else
23 if [ ! -f $FILE2 ];
24 then
25 echo " error: file $FILE2 does not exist. Abort."
26 else
27 echo " building archive... "
28 ar rs $ARC $FILE1 $FILE2
29
31 # lib
32 cp $ARC $LIB
34
35 # include
36 cp $HEADER1 $INCLUDE
37 cp $HEADER2 $INCLUDE
39
41 fi
42 fi
So, if I were to group all files into ONE variable like:
FILE="obj1.o obj2.o ... "
How would I check the existence of each file, and copy them(headers)? I can only do this one by one, which will be soon unacceptable.
Here is what I came up with to help you.
The best way to do this is using an array for FILE
short example to implement what you are trying to do:
# !/bin/bash
#define an array of files to look for
FILES=("SDL_Logger.h" "SDL_Initializer.h" "libsdlhelpere.o")
#define your directories
INCLUDE=~/include
LIB=~/lib
#set the amount of entries in our array
SIZE=${#FILES[#]}
# use for loop read all FILES
for (( i=0; i<${SIZE}; i++ ));
do
echo "checking for file: "${FILES[$i]}
if [ ! -f ${FILES[$i]} ];
then
echo " error: file"${FILES[$i]}" does not exist. Abort."
else
echo " building archive... "
fi
done
Here we define FILES as our array
FILES=("SDL_Logger.h" "SDL_Initializer.h" "libsdlhelpere.a")
then we Find the size of files
SIZE=${#FILES[#]}
Then we go through each file and execute a command which is echo and then our if statement:
for (( i=0; i<${SIZE}; i++ ));
do
Here is how we call our item in the array...
${FILES[$i]}
so in what we are doing in plain english is:
echo FILES[1]....
IF FILES[1] doesn't exist then error....
else execute building archive...
echo FILES[2]....
IF FILES[2] doesn't exist then error...
etc...
This will repeat until the SIZE of FILES in met.
Using this method you can also just define the beginning part of the file name such as
"SDL_Initializer" and have your loop add in the .o .h. .a etc... Maybe another array FILETYPES ;)
hope this helped...
Sorry I didn't complete the code for you :)
Here is an answer to the question as asked:
#!/bin/bash
FILES="SDL_Logger.o SDL_Initializer.o"
HEADERS="${FILES//.o/.h}"
ARC="libsdlhelper.a"
INCLUDE=~/include
LIB=~/lib
for f in ${FILES}; do
if [ ! -f "${f}" ]; then
echo "error: file ${f} does not exist. Abort."
exit 1
fi
done
ar rs ${ARC} ${FILES}
cp ${ARC} ${LIB}
cp ${HEADERS} ${INCLUDE}
However, as the comments point out, the right tool for this job is make. For example GNU make. If you plan on developing software on a unix platform, investing time learning make is time well spent.

Resources