Problems with compiling using [OS Specific toolchain]
Posted: Wed Sep 27, 2017 12:57 pm
Hi,
For the past 2 weeks I've been trying to set up the OS Specific Toolchain.
All goes well until I try to compile a userspace C file with it.
I've created a pretty automated build process for the toolchain
Here are the steps that are performed by my bash scripts:
1. Download Sources:
- GCC 6.3.0, Binutils 2.27, Newlib 2.5.0, Autoconf 2.64 & 2.65 + Automake 1.11 & 1.11.6
2. Untar them
3. Build Generic elf target toolchain from GCC and Binutils (this works perfectly fine and compiles my kernel correctly)
4. Build automake and autoconf as 3 isolated combinations
- standalone autoconf2.64
- autoconf2.65 + automake1.11 (installing into the same ../bin/ directory)
- autoconf2.64 + automake1.11.6 (as above)
5. Prepare all required things for Newlib (crt0.s, crti.s, crtn.s, syscall definitions etc.)
6. Patch Newlib using awk and sed
7. Run autoconf and automake as documented in the "Porting Newlib" tutorial on the wiki
8. Build Newlib (works fine)
9. Patch Binutils using sed and awk
10. Build Binutils as documented in the "OS Specific Toolchain" tutorial (builds without any errors)
11. Patch GCC using sed and awk
12. Build GCC (same as for Binutils) (also reports no errors during the build process)
All of this seems to work perfectly fine until I actually try to use these tools
I should probably also add that I've tried the above with multiple versions of Binutils and GCC without any luck.
(GCC 7.1.0, Binutils 2.28 and more...)
The problem:
Im trying to compile a very simple test.c file using my toolchain like this
As you can see GCC is finding my crt0, crti and crtn files perfectly fine.
I can also see in the warnings that it tries to do something with the init and fini sections which are in my crt files.
I've tried searching for anwers on the Forum and Google but I couldn't find anything about "ld terminated with signal 11, segfault, core dumped" and those warnings.
Just to give you some more background, here are the contents of my crt files, syscall definitions and the patches I apply to Newlib, Binutils and GCC:
crt0.s:
crti.s:
crtn.s:
bootstrap.c as part of newlib build:
Newlib patch:
Binutils patch:
GCC Patch 1:
At this point, Im running autoconf in libstdc++-v3 dir
GCC patch 2:
For the past 2 weeks I've been trying to set up the OS Specific Toolchain.
All goes well until I try to compile a userspace C file with it.
I've created a pretty automated build process for the toolchain
Here are the steps that are performed by my bash scripts:
1. Download Sources:
- GCC 6.3.0, Binutils 2.27, Newlib 2.5.0, Autoconf 2.64 & 2.65 + Automake 1.11 & 1.11.6
2. Untar them
3. Build Generic elf target toolchain from GCC and Binutils (this works perfectly fine and compiles my kernel correctly)
4. Build automake and autoconf as 3 isolated combinations
- standalone autoconf2.64
- autoconf2.65 + automake1.11 (installing into the same ../bin/ directory)
- autoconf2.64 + automake1.11.6 (as above)
5. Prepare all required things for Newlib (crt0.s, crti.s, crtn.s, syscall definitions etc.)
6. Patch Newlib using awk and sed
7. Run autoconf and automake as documented in the "Porting Newlib" tutorial on the wiki
8. Build Newlib (works fine)
9. Patch Binutils using sed and awk
10. Build Binutils as documented in the "OS Specific Toolchain" tutorial (builds without any errors)
11. Patch GCC using sed and awk
12. Build GCC (same as for Binutils) (also reports no errors during the build process)
All of this seems to work perfectly fine until I actually try to use these tools
I should probably also add that I've tried the above with multiple versions of Binutils and GCC without any luck.
(GCC 7.1.0, Binutils 2.28 and more...)
The problem:
Im trying to compile a very simple test.c file using my toolchain like this
Code: Select all
damian@damian-Lenovo-Y50-70:~/Desktop/DBOS/apps$ ../build_tools/toolchain/host/bin/i686-dbos-gcc -v -o test test.c
Using built-in specs.
COLLECT_GCC=../build_tools/toolchain/host/bin/i686-dbos-gcc
COLLECT_LTO_WRAPPER=/home/damian/Desktop/DBOS/build_tools/toolchain/host/libexec/gcc/i686-dbos/6.3.0/lto-wrapper
Target: i686-dbos
Configured with: /home/damian/Desktop/DBOS/build_tools/sources/host_gcc-6.3.0/configure --target=i686-dbos --prefix=/home/damian/Desktop/DBOS/build_tools/toolchain/host --with-sysroot=/home/damian/Desktop/DBOS/sysroot --enable-languages=c,c++
Thread model: single
gcc version 6.3.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 'test' '-fPIE' '-mtune=generic' '-march=pentiumpro'
/home/damian/Desktop/DBOS/build_tools/toolchain/host/libexec/gcc/i686-dbos/6.3.0/cc1 -quiet -v test.c -quiet -dumpbase test.c -mtune=generic -march=pentiumpro -auxbase test -version -fPIE -o /tmp/ccZHbSxc.s
GNU C11 (GCC) version 6.3.0 (i686-dbos)
compiled by GNU C version 6.3.0 20170406, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/home/damian/Desktop/DBOS/sysroot/usr/local/include"
ignoring nonexistent directory "/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/include"
#include "..." search starts here:
#include <...> search starts here:
/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/include
/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/include-fixed
/home/damian/Desktop/DBOS/sysroot/usr/include
End of search list.
GNU C11 (GCC) version 6.3.0 (i686-dbos)
compiled by GNU C version 6.3.0 20170406, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 24d62e71f8cbce4777182df57909d083
COLLECT_GCC_OPTIONS='-v' '-o' 'test' '-fPIE' '-mtune=generic' '-march=pentiumpro'
/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/bin/as -v -o /tmp/cc6gHlt4.o /tmp/ccZHbSxc.s
GNU assembler version 2.27 (i686-dbos) using BFD version (GNU Binutils) 2.27
COMPILER_PATH=/home/damian/Desktop/DBOS/build_tools/toolchain/host/libexec/gcc/i686-dbos/6.3.0/:/home/damian/Desktop/DBOS/build_tools/toolchain/host/libexec/gcc/i686-dbos/6.3.0/:/home/damian/Desktop/DBOS/build_tools/toolchain/host/libexec/gcc/i686-dbos/:/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/:/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/:/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/bin/
LIBRARY_PATH=/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/:/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/lib/:/home/damian/Desktop/DBOS/sysroot/lib/:/home/damian/Desktop/DBOS/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'test' '-fPIE' '-mtune=generic' '-march=pentiumpro'
/home/damian/Desktop/DBOS/build_tools/toolchain/host/libexec/gcc/i686-dbos/6.3.0/collect2 -plugin /home/damian/Desktop/DBOS/build_tools/toolchain/host/libexec/gcc/i686-dbos/6.3.0/liblto_plugin.so -plugin-opt=/home/damian/Desktop/DBOS/build_tools/toolchain/host/libexec/gcc/i686-dbos/6.3.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccOBMjpW.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc --sysroot=/home/damian/Desktop/DBOS/sysroot -o test /home/damian/Desktop/DBOS/sysroot/usr/lib/crt0.o /home/damian/Desktop/DBOS/sysroot/usr/lib/crti.o -L/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0 -L/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/lib -L/home/damian/Desktop/DBOS/sysroot/lib -L/home/damian/Desktop/DBOS/sysroot/usr/lib /tmp/cc6gHlt4.o -lgcc -lc -lgcc /home/damian/Desktop/DBOS/sysroot/usr/lib/crtn.o
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/bin/ld: test: warning: allocated section `.init' not in segment
/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/bin/ld: test: warning: allocated section `.text' not in segment
/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/bin/ld: test: warning: allocated section `.fini' not in segment
/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/bin/ld: test: warning: allocated section `.rodata' not in segment
/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/bin/ld: test: warning: allocated section `.eh_frame' not in segment
/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/bin/ld: test: warning: allocated section `.got.plt' not in segment
/home/damian/Desktop/DBOS/build_tools/toolchain/host/lib/gcc/i686-dbos/6.3.0/../../../../i686-dbos/bin/ld: test: warning: allocated section `.data' not in segment
I can also see in the warnings that it tries to do something with the init and fini sections which are in my crt files.
I've tried searching for anwers on the Forum and Google but I couldn't find anything about "ld terminated with signal 11, segfault, core dumped" and those warnings.
Just to give you some more background, here are the contents of my crt files, syscall definitions and the patches I apply to Newlib, Binutils and GCC:
crt0.s:
Code: Select all
SECTION .text
GLOBAL _start
EXTERN bootstrap_stage_1
EXTERN main
_start:
push main
call bootstrap_stage_1
Code: Select all
SECTION .init
GLOBAL _bootstrap_stage_2
_bootstrap_stage_2:
push ebp
SECTION .fini
GLOBAL _de_bootstrap
_de_bootstrap:
push ebp
Code: Select all
SECTION .init
pop ebp
ret
SECTION .fini
pop ebp
ret
Code: Select all
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/times.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdint.h>
extern char ** environ;
extern void _bootstrap_stage_2;
extern int _exit();
#define int (*main_t)(int argc, char ** argv)
void bootstrap_stage_1(main_t main, int arguments_count, char * arguments_values[]){
environ = NULL;
_bootstrap_stage_2();
int retval = main(arguments_count, arguments_values);
_exit(retval);
}
Code: Select all
#!/bin/bash
WD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VER_NEWLIB="newlib-2.5.0"
NEWLIB_SOURCEDIR=$WD/../sources/${VER_NEWLIB}/
if [ ! -f $NEWLIB_SOURCEDIR/.patched ]; then
sed -r 's:(\-plan9\* \\):\-plan9\* \| \-dbos\* \\:' < $NEWLIB_SOURCEDIR/config.sub > $WD/config.sub.tmp
cp $WD/config.sub.tmp $NEWLIB_SOURCEDIR/config.sub
rm $WD/config.sub.tmp
touch $NEWLIB_SOURCEDIR/.patched
fi
if [ ! -f $NEWLIB_SOURCEDIR/newlib/.patched ]; then
awk '{ print }
/^case "\$\{host\}\" in$/ {
print "\ti[3-7]86-*-dbos*)"
print "\t\t\tsysdir=dbos"
print "\t\t\t;;"
}' < $NEWLIB_SOURCEDIR/newlib/configure.host > $WD/configure.host.tmp
cp $WD/configure.host.tmp $NEWLIB_SOURCEDIR/newlib/configure.host
rm $WD/configure.host.tmp
touch $NEWLIB_SOURCEDIR/newlib/.patched
fi
if [ ! -f $NEWLIB_SOURCEDIR/newlib/libc/sys/.patched ]; then
awk '{ print }
/case \$\{sys_dir\} in$/ {
print "\tdbos) AC_CONFIG_SUBDIRS(dbos) ;;"
}' < $NEWLIB_SOURCEDIR/newlib/libc/sys/configure.in > $WD/configure.in.tmp
cp $WD/configure.in.tmp $NEWLIB_SOURCEDIR/newlib/libc/sys/configure.in
rm $WD/configure.in.tmp
touch $NEWLIB_SOURCEDIR/newlib/libc/sys/.patched
fi
Code: Select all
#!/bin/bash
WD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BINUTILS_VER="binutils-2.27"
BINUTILS_SOURCEDIR=$WD/../sources/host_${BINUTILS_VER}
if [ ! -f $BINUTILS_SOURCEDIR/.patched ]; then
sed -r 's:(\-plan9\* \\):\-plan9\* \| \-dbos\* \\:' < $BINUTILS_SOURCEDIR/config.sub > $WD/config.sub.tmp
cp $WD/config.sub.tmp $BINUTILS_SOURCEDIR/config.sub
rm -rf $WD/config.sub.tmp
touch $BINUTILS_SOURCEDIR/.patched
fi
if [ ! -f $BINUTILS_SOURCEDIR/bfd/.patched ]; then
awk ' { print }
/# START OF targmatch.h/{
print "\ti[3-7]86-*-dbos*)"
print "\t\ttarg_defvec=i386_elf32_vec"
print "\t\ttarg_selvec="
print "\t\t;;"
print ""
}
' < $BINUTILS_SOURCEDIR/bfd/config.bfd > $WD/config.bfd.tmp
cp $WD/config.bfd.tmp $BINUTILS_SOURCEDIR/bfd/config.bfd
rm -rf $WD/config.bfd.tmp
touch $BINUTILS_SOURCEDIR/bfd/.patched
fi
if [ ! -f $BINUTILS_SOURCEDIR/gas/.patched ]; then
awk ' { print }
/case \$\{generic_target\} in$/{
print "\ti386-*-dbos*)\t\t\tfmt=elf;;"
print ""
}
' < $BINUTILS_SOURCEDIR/gas/configure.tgt > $WD/configure.tgt.tmp
cp $WD/configure.tgt.tmp $BINUTILS_SOURCEDIR/gas/configure.tgt
rm -rf $WD/configure.tgt.tmp
touch $BINUTILS_SOURCEDIR/gas/.patched
fi
if [ ! -f $BINUTILS_SOURCEDIR/ld/.patched ]; then
awk ' { print }
/^case "\$\{targ\}" in$/{
print "i[3-7]86-*-dbos*)"
print "\t\t\ttarg_emul=elf_i386_dbos"
print "\t\t\ttarg_extra_emuls=elf_i386"
print "\t\t\t;;"
}
' < $BINUTILS_SOURCEDIR/ld/configure.tgt > $WD/configure.tgt.tmp
cp $WD/configure.tgt.tmp $BINUTILS_SOURCEDIR/ld/configure.tgt
rm -rf $WD/configure.tgt.tmp
touch $BINUTILS_SOURCEDIR/ld/.patched
fi
if [ ! -f $BINUTILS_SOURCEDIR/ld/emulparams/elf_i386_dbos.sh ]; then
touch $BINUTILS_SOURCEDIR/ld/emulparams/elf_i386_dbos.sh
echo 'SCRIPT_NAME=elf
OUTPUT_FORMAT="elf32-i386"
TEXT_START_ADDR=0x08000000
MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
ARCH=i386
MACHINE=
NOP=0x90909090
GENERATE_SHLIB_SCRIPT=yes
GENERATE_PIE_SCRIPT=yes
NO_SMALL_DATA=yes
SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 12 ? 12 : 0"
IREL_IN_PLT=
' > $BINUTILS_SOURCEDIR/ld/emulparams/elf_i386_dbos.sh
fi
if [ ! -f $BINUTILS_SOURCEDIR/ld/.patched2 ]; then
awk ' { print }
/eelf_i386.c \\/{
print "\teelf_i386_dbos.c \\"
}
/eelf_i386.c: \$\(srcdir\)\/emulparams\/elf_i386.sh \\/{
getline; print $0
getline; print $0
print "eelf_i386_dbos.c: $(srcdir)/emulparams/elf_i386_dbos.sh \\"
print "\t$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}"
print "\t\t${GENSCRIPTS} elf_i386_dbos \"$(tdir_elf_i386_dbos)\""
print ""
}
' < $BINUTILS_SOURCEDIR/ld/Makefile.am > $WD/Makefile.am.tmp
cp $WD/Makefile.am.tmp $BINUTILS_SOURCEDIR/ld/Makefile.am
rm -rf $WD/Makefile.am.tmp
touch $BINUTILS_SOURCEDIR/ld/.patched2
fi
Code: Select all
WD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
GCC_VER="gcc-6.3.0"
GCC_SOURCEDIR=$WD/../sources/host_${GCC_VER}
if [ ! -f $GCC_SOURCEDIR/.patched ]; then
sed -r 's:(\-plan9\* \\):\-plan9\* \| \-dbos\* \\:' < $GCC_SOURCEDIR/config.sub > $WD/config.sub.tmp
cp $WD/config.sub.tmp $GCC_SOURCEDIR/config.sub
rm $WD/config.sub.tmp
touch $GCC_SOURCEDIR/.patched
fi
if [ ! -f $GCC_SOURCEDIR/gcc/.patched ]; then
awk ' { print }
/# Common parts for widely ported systems./{
getline; print $0
print "*-*-dbos*)"
print "\tgas=yes"
print "\tgnu_ld=yes"
print "\tdefault_use_cxa_atexit=yes"
print "\t;;"
}
/i\[34567\]86\-\*\-dragonfly\*\)/{
getline; print $0
getline; print $0
getline; print $0
getline; print $0
getline; print $0
getline; print $0
getline; print $0
print "i[34567]86-*-dbos*)"
print "\ttm_file=\"${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h dbos.h\""
print "\t;;"
}
' < $GCC_SOURCEDIR/gcc/config.gcc > $WD/config.gcc.tmp
cp $WD/config.gcc.tmp $GCC_SOURCEDIR/gcc/config.gcc
rm -rf $WD/config.gcc.tmp
touch $GCC_SOURCEDIR/gcc/.patched
fi
if [ ! -f $GCC_SOURCEDIR/gcc/config/dbos.h ]; then
touch $GCC_SOURCEDIR/gcc/config/dbos.h
echo '
#undef TARGET_DBOS
#define TARGET_DBOS 1
#define LIB_SPEC "-lc"
#undef STARTFILE_SPEC
#define STARTFILE_SPEC "crt0.o%s crti.o%s"
#undef ENDFILE_SPEC
#define ENDFILE_SPEC "crtn.o%s"
#undef NO_IMPLICIT_EXTERN_C
#define NO_IMPLICIT_EXTERN_C 1
' > $GCC_SOURCEDIR/gcc/config/dbos.h
fi
if [ ! -f $GCC_SOURCEDIR/libstdc++-v3/.patched ]; then
awk ' { print }
/\*\-darwin\*\)/{
getline; print $0
getline; print $0
getline; print $0
getline; print $0
getline; print $0
getline; print $0
getline; print $0
getline; print $0
getline; print $0
print "\t*-dbos*)"
print "\t\tGLIBCXX_CHECK_COMPILER_FEATURES"
print "\t\tGLIBCXX_CHECK_LINKER_FEATURES"
print "\t\tGLIBCXX_CHECK_MATH_SUPPORT"
print "\t\tGLIBCXX_CHECK_STDLIB_SUPPORT"
print "\t\t;;"
print ""
}
' < $GCC_SOURCEDIR/libstdc++-v3/crossconfig.m4 > $WD/crossconfig.m4.tmp
cp $WD/crossconfig.m4.tmp $GCC_SOURCEDIR/libstdc++-v3/crossconfig.m4
rm -rf $WD/crossconfig.m4.tmp
touch $GCC_SOURCEDIR/libstdc++-v3/.patched
fi
GCC patch 2:
Code: Select all
WD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
GCC_VER="gcc-6.3.0"
GCC_SOURCEDIR=$WD/../sources/host_${GCC_VER}
if [ ! -f $GCC_SOURCEDIR/libgcc/.patched ]; then
awk ' { print }
/i\[34567\]86\-\*\-dragonfly\*\)/{
getline; print $0
getline; print $0
getline; print $0
print "i[34567]86-*-dbos*)"
print "\t;;"
}
' < $GCC_SOURCEDIR/libgcc/config.host > $WD/config.host.tmp
cp $WD/config.host.tmp $GCC_SOURCEDIR/libgcc/config.host
rm -rf $WD/config.host.tmp
touch $GCC_SOURCEDIR/libgcc/.patched
fi
if [ ! -f $GCC_SOURCEDIR/fixincludes/.patched ]; then
awk ' { print }
/case \$machine in/{
print "\t\t*-dbos* | \\"
}
' < $GCC_SOURCEDIR/fixincludes/mkfixinc.sh > $WD/mkfixinc.sh.tmp
cp $WD/mkfixinc.sh.tmp $GCC_SOURCEDIR/fixincludes/mkfixinc.sh.tmp
rm -rf $WD/mkfixinc.sh.tmp
touch $GCC_SOURCEDIR/fixincludes/.patched
fi