Autor Thema: GCC für OS compilieren  (Gelesen 20547 mal)

MNemo

  • Beiträge: 547
    • Profil anzeigen
Gespeichert
« Antwort #20 am: 11. July 2015, 12:40 »
Für mich sieht es so aus als würde in i386.md etwas bezüglich der Code-Generierung konfiguriert.

Und wenn du dir mal gcc/config.gcc angesehn hast, das ist die einzige Datei in der i386/att.h mal erwähnt wird. Passiert das abhängig vom Compiler TARGET.

Ich nehme also an du musst für dein TARGET in tm_file i386/atth mit aufnehmen.

Oder dein Target so umbenennen das es auf eine dieser Zeilen passt.

Code: (gcc/config.gcc) [Auswählen]
1368 i[34567]86-*-elf*)                                                                                                                                                         
1369     tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h"
1370     ;;
1371 x86_64-*-elf*)
1372     tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h"
1373     ;;
„Wichtig ist nicht, besser zu sein als alle anderen. Wichtig ist, besser zu sein als du gestern warst!“

OsDevNewbie

  • Beiträge: 282
    • Profil anzeigen
    • YourOS Kernel
Gespeichert
« Antwort #21 am: 12. July 2015, 02:21 »
Hier ist ein git Repository mit den Änderungen von mir: https://github.com/Gurgel100/gcc
Hier ist noch der dazugehörige Patch:
diff --git a/config.sub b/config.sub
index 6d2e94c..71fcbe5 100755
--- a/config.sub
+++ b/config.sub
@@ -118,7 +118,7 @@ case $maybe_os in
   nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
   linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
   knetbsd*-gnu* | netbsd*-gnu* | \
-  kopensolaris*-gnu* | \
+  kopensolaris*-gnu* | youros* | \
   storm-chaos* | os2-emx* | rtmk-nova*)
     os=-$maybe_os
     basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
@@ -1526,6 +1526,9 @@ case $os in
  -nacl*)
  ;;
  -none)
+ ;;
+ -youros*)
+ os=-youros
  ;;
  *)
  # Get rid of the `-' at the beginning of $os.
diff --git a/fixincludes/mkfixinc.sh b/fixincludes/mkfixinc.sh
index 6653fed..ef2f2ab 100755
--- a/fixincludes/mkfixinc.sh
+++ b/fixincludes/mkfixinc.sh
@@ -11,6 +11,7 @@ target=fixinc.sh
 
 # Check for special fix rules for particular targets
 case $machine in
+ *-youros* | \
     i?86-*-cygwin* | \
     i?86-*-mingw32* | \
     x86_64-*-mingw32* | \
diff --git a/gcc/config.gcc b/gcc/config.gcc
index cb08a5c..6bbcc00 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -868,6 +868,11 @@ case ${target} in
     *) echo 'Unknown thread configuration for VxWorks'; exit 1 ;;
   esac
   ;;
+*-*-youros*)
+  gas=yes
+  gnu_ld=yes
+  default_use_cxa_atexit=no
+  ;;
 *-*-elf|arc*-*-elf*)
   # Assume that newlib is being used and so __cxa_atexit is provided.
   default_use_cxa_atexit=yes
@@ -1739,6 +1744,8 @@ i[34567]86-*-interix[3-9]*)
  tm_file="${tm_file} dbxcoff.h"
  fi
  ;;
+x86_64-*-youros*)
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h i386/i386elf.h i386/x86-64.h youros.h"
 ia64*-*-elf*)
  tm_file="${tm_file} dbxelf.h elfos.h newlib-stdint.h ia64/sysv4.h ia64/elf.h"
  tmake_file="ia64/t-ia64"
diff --git a/libgcc/config.host b/libgcc/config.host
index 4b15895..cee3721 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -718,6 +718,10 @@ x86_64-*-mingw*)
  extra_parts="$extra_parts vtv_start.o vtv_end.o vtv_start_preinit.o vtv_end_preinit.o"
  fi
  ;;
+x86_64-*-youros*)
+ extra_parts="$extra_parts crtbegin.o crtend.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
+ ;;
 i[34567]86-*-interix[3-9]*)
  tmake_file="$tmake_file i386/t-interix i386/t-chkstk"
  ;;
diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4
index 10247f9..8c5ffac 100644
--- a/libstdc++-v3/crossconfig.m4
+++ b/libstdc++-v3/crossconfig.m4
@@ -269,6 +269,12 @@ case "${host}" in
     AC_DEFINE(HAVE_TANF)
     AC_DEFINE(HAVE_TANHF)
     ;;
+  *-youros*)
+ GLIBCXX_CHECK_COMPILER_FEATURES
+ GLIBCXX_CHECK_LINKER_FEATURES
+ GLIBCXX_CHECK_MATH_SUPPORT
+ GLIBCXX_CHECK_STDLIB_SUPPORT
+ ;;
   *)
     AC_MSG_ERROR([No support for this host/target combination.])
    ;;
Viele Grüsse
OsDevNewbie

Ein Computer ohne Betriebsystem ist nicht mehr wert als ein Haufen Schrott.
Ein Computer ist eine Maschine, die einem Lebewesen das kostbarste klaut, was sie selber nicht hat:
DIE ZEIT DES LEBENS

MNemo

  • Beiträge: 547
    • Profil anzeigen
Gespeichert
« Antwort #22 am: 12. July 2015, 11:42 »
Ist die fehlermeldung schon von diesem Code?

Hier erst mal ein Fix:
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 6bbcc00..68b3f7e 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1746,6 +1746,7 @@ i[34567]86-*-interix[3-9]*)
        ;;
 x86_64-*-youros*)
        tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h i386/i386elf.h i386/x86-64.h youros.h"
+       ;;
 ia64*-*-elf*)
        tm_file="${tm_file} dbxelf.h elfos.h newlib-stdint.h ia64/sysv4.h ia64/elf.h"
        tmake_file="ia64/t-ia64"

Wie compilierst du? Was sind die Konfigurationsparameter?

Eventuell könnte das hier beim Debuggen helfen:
$ env -i sh -c 'set -a;target=x86_64-unknown-youros;source gcc/config.gcc;env' > /tmp/youros
$ env -i sh -c 'set -a;target=x86_64-redhat-linux-gnu;source gcc/config.gcc;env' > /tmp/redhat
$ diff -u3 /tmp/youros /tmp/redhat
Es zeigt den unterschied zwischen zwei Target Configurationne an. x86_64-unknown-youros und x86_64-redhat-linux-gnu
„Wichtig ist nicht, besser zu sein als alle anderen. Wichtig ist, besser zu sein als du gestern warst!“

OsDevNewbie

  • Beiträge: 282
    • Profil anzeigen
    • YourOS Kernel
Gespeichert
« Antwort #23 am: 12. July 2015, 14:05 »
Ist die fehlermeldung schon von diesem Code?
Ja die Fehlermeldung ist von diesem Code.
Danke für deinen Fix. Ich glaube es funktioniert jetzt. Auf jeden Fall kommt jetzt die nächste Fehlermeldung:
g++ -c   -g -O2 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -DGENERATOR_FILE -I. -Ibuild -I../.././gcc -I../.././gcc/build -I../.././gcc/../include  -I../.././gcc/../libcpp/include  \
-o build/genpreds.o ../.././gcc/genpreds.c
In file included from ./tm.h:24:0,
                 from ../.././gcc/genpreds.c:26:
../.././gcc/config/youros.h:13:8: error: attempt to use poisoned "STANDARD_INCLUDE_DIR"
 #undef STANDARD_INCLUDE_DIR
        ^
../.././gcc/config/youros.h:14:9: error: attempt to use poisoned "STANDARD_INCLUDE_DIR"
 #define STANDARD_INCLUDE_DIR ="/lib/include"
         ^
make[1]: *** [build/genpreds.o] Fehler 1
make[1]: Verzeichnis »/home/pascal/Dokumente/cross/src/gcc-5.1.0/host-x86_64-unknown-linux-gnu/gcc« wird verlassen
make: *** [all-gcc] Fehler 2
Was muss ich denn jetzt anstelle von STANDARD_INCLUDE_DIR verwenden? Kann man das irgendwo nachsehen, was man da alles für Makros definieren kann?
Ich danke vielmals für eure Antworten.
Viele Grüsse
OsDevNewbie

Ein Computer ohne Betriebsystem ist nicht mehr wert als ein Haufen Schrott.
Ein Computer ist eine Maschine, die einem Lebewesen das kostbarste klaut, was sie selber nicht hat:
DIE ZEIT DES LEBENS

MNemo

  • Beiträge: 547
    • Profil anzeigen
Gespeichert
« Antwort #24 am: 12. July 2015, 14:18 »
grep sagt zu dem Makro, das du der einzige bist der es nutzt und
Code: (gcc/system.h) [Auswählen]
869 /* Other obsolete target macros, or macros that used to be in target
870    headers and were not used, and may be obsolete or may never have
871    been used.  */

gcc/config.gcc hat am Anfang eine liste mit variablen und deren Beschreibung. (native_system_header_dir)
„Wichtig ist nicht, besser zu sein als alle anderen. Wichtig ist, besser zu sein als du gestern warst!“

OsDevNewbie

  • Beiträge: 282
    • Profil anzeigen
    • YourOS Kernel
Gespeichert
« Antwort #25 am: 18. July 2015, 02:38 »
Habe ich das richtig verstanden, dass in "native_system_header_dir" die Headerdateien der Library meines OS's sein müssen?
Und welche Binaries muss ich jetzt benutzen zum kompilieren? Ich habe nämlich einen bin Ordner und dann und dort sind die Binaries mit dem Namen x86_64-pc-youros-* und dann hab ich noch einen Ordner mit dem Namen x86_64-pc-youros/bin und dort befinden sich nochmal einige Binaries (so wie ich das sehe vor allem von binutils).
Ich danke euch nochmals für eure Antworten.
« Letzte Änderung: 18. July 2015, 02:44 von OsDevNewbie »
Viele Grüsse
OsDevNewbie

Ein Computer ohne Betriebsystem ist nicht mehr wert als ein Haufen Schrott.
Ein Computer ist eine Maschine, die einem Lebewesen das kostbarste klaut, was sie selber nicht hat:
DIE ZEIT DES LEBENS

OsDevNewbie

  • Beiträge: 282
    • Profil anzeigen
    • YourOS Kernel
Gespeichert
« Antwort #26 am: 25. July 2015, 15:31 »
Es hat soweit alles geklappt und ich habe jetzt mal versucht eine kleine Anwendung zu kompilieren und zwar so:
~/Dokumente/test/env/bin/x86_64-pc-youros-gcc -v -o main main.c
Und ich bekomme folgende Fehlermeldung:
/tmp/cci2MKYd.o: In function `thread':
main.c:(.text+0x5): relocation truncated to fit: R_X86_64_32 against `.rodata'
/tmp/cci2MKYd.o: In function `main':
main.c:(.text+0x30): relocation truncated to fit: R_X86_64_32 against `.rodata'
main.c:(.text+0x73): relocation truncated to fit: R_X86_64_32 against symbol `thread' defined in .text section in /tmp/cci2MKYd.o
main.c:(.text+0x7d): relocation truncated to fit: R_X86_64_32 against `.rodata'
main.c:(.text+0x82): relocation truncated to fit: R_X86_64_32 against `.rodata'
main.c:(.text+0x97): relocation truncated to fit: R_X86_64_32 against `.rodata'
/tmp/cci2MKYd.o: In function `parseFile':
main.c:(.text+0x11c): relocation truncated to fit: R_X86_64_32 against `.rodata'
main.c:(.text+0x18d): relocation truncated to fit: R_X86_64_32 against `.rodata'
main.c:(.text+0x1bc): relocation truncated to fit: R_X86_64_32 against `.rodata'
main.c:(.text+0x1cd): relocation truncated to fit: R_X86_64_32 against `.rodata'
collect2: error: ld returned 1 exit status
Ich verstehe aber nicht wieso die .text und die .rodata Sektionen soweit auseinander sein sollten. Bei Binutils habe ich einfach nur elf-x86-64.sh in mein Skript eingebunden und die TEXT_START_ADDRESS geändert. Muss ich da noch mehr ändern?
Viele Grüsse
OsDevNewbie

Ein Computer ohne Betriebsystem ist nicht mehr wert als ein Haufen Schrott.
Ein Computer ist eine Maschine, die einem Lebewesen das kostbarste klaut, was sie selber nicht hat:
DIE ZEIT DES LEBENS

MNemo

  • Beiträge: 547
    • Profil anzeigen
Gespeichert
« Antwort #27 am: 25. July 2015, 17:13 »
Es sieht so aus als würde er beim linken versuchen 64-Bit Adressen in ein 32-Bit Format zu stopfen.

Hilft ein '-m64' ?

Produziert youros-gcc 64-Bit elf (beim compiliren / linken)?

welches format haben die anderen dateien, gegen die du likst (crt0, oder wie die heißt)

„Wichtig ist nicht, besser zu sein als alle anderen. Wichtig ist, besser zu sein als du gestern warst!“

OsDevNewbie

  • Beiträge: 282
    • Profil anzeigen
    • YourOS Kernel
Gespeichert
« Antwort #28 am: 26. July 2015, 00:26 »
Hilft ein '-m64' ?
Nein.

Also meine Emulparams/elf_x86_64_youros.em sieht so aus:
. ${srcdir}/emulparams/elf_x86_64.sh
TEXT_START_ADDR=0x8000000000
Und die elf_x86_64.sh sieht so aus:
. ${srcdir}/emulparams/plt_unwind.sh
SCRIPT_NAME=elf
ELFSIZE=64
OUTPUT_FORMAT="elf64-x86-64"
NO_REL_RELOCS=yes
TEXT_START_ADDR=0x400000
MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
ARCH="i386:x86-64"
MACHINE=
TEMPLATE_NAME=elf32
GENERATE_SHLIB_SCRIPT=yes
GENERATE_PIE_SCRIPT=yes
NO_SMALL_DATA=yes
LARGE_SECTIONS=yes
LARGE_BSS_AFTER_BSS=
SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 24 ? 24 : 0"
IREL_IN_PLT=
# Reuse TINY_READONLY_SECTION which is placed right after .plt section.
TINY_READONLY_SECTION=".plt.bnd      ${RELOCATING-0} : { *(.plt.bnd) }"

if [ "x${host}" = "x${target}" ]; then
  case " $EMULATION_LIBPATH " in
    *" ${EMULATION_NAME} "*)
      NATIVE=yes
  esac
fi

# Linux/Solaris modify the default library search path to first include
# a 64-bit specific directory.
case "$target" in
  x86_64*-linux*|i[3-7]86-*-linux-*)
    case "$EMULATION_NAME" in
      *64*)
        LIBPATH_SUFFIX=64
        BNDPLT=yes
        ;;
    esac
    ;;
  *-*-solaris2*)
    LIBPATH_SUFFIX=/amd64
    ELF_INTERPRETER_NAME=\"/lib/amd64/ld.so.1\"
  ;;
esac

Alle Objekt Dateien sind 64-bit.

Produziert youros-gcc 64-Bit elf (beim compiliren / linken)?
Ich vermute eher, dass die Sektionen zu weit ausseinander liegen, so dass eine 32-bit relative Addresse nicht mehr ausreicht.
Viele Grüsse
OsDevNewbie

Ein Computer ohne Betriebsystem ist nicht mehr wert als ein Haufen Schrott.
Ein Computer ist eine Maschine, die einem Lebewesen das kostbarste klaut, was sie selber nicht hat:
DIE ZEIT DES LEBENS

Svenska

  • Beiträge: 1 792
    • Profil anzeigen
Gespeichert
« Antwort #29 am: 26. July 2015, 01:09 »
Ist das Absicht, dass in deinem Script was von i386 und elf32 steht?

OsDevNewbie

  • Beiträge: 282
    • Profil anzeigen
    • YourOS Kernel
Gespeichert
« Antwort #30 am: 26. July 2015, 02:54 »
Ich dachte das muss so sein. Ich habe folgende Anleitung verwendet:
http://wiki.osdev.org/OS_Specific_Toolchain
Viele Grüsse
OsDevNewbie

Ein Computer ohne Betriebsystem ist nicht mehr wert als ein Haufen Schrott.
Ein Computer ist eine Maschine, die einem Lebewesen das kostbarste klaut, was sie selber nicht hat:
DIE ZEIT DES LEBENS

MNemo

  • Beiträge: 547
    • Profil anzeigen
Gespeichert
« Antwort #31 am: 26. July 2015, 12:50 »
Zitat
TEXT_START_ADDR=0x8000000000

Passt nicht in 32-Bit. Also musst du entweder auf die Platzsparende Variante von 32-Bit Adressen verzichten, oder deinen Code wo anders hinlegen.


[edit]
-fpic könnte aber evtl auch helfen.
« Letzte Änderung: 26. July 2015, 12:57 von MNemo »
„Wichtig ist nicht, besser zu sein als alle anderen. Wichtig ist, besser zu sein als du gestern warst!“

OsDevNewbie

  • Beiträge: 282
    • Profil anzeigen
    • YourOS Kernel
Gespeichert
« Antwort #32 am: 26. July 2015, 23:48 »
-fpic könnte aber evtl auch helfen.
So funktioniert es. Es gibt auf jeden Fall keine Fehlermeldung mehr. Wo muss ich das Einstellen, dass der gcc dieses Flag automatisch einsetzt?

Danke für eure Hilfe.
Viele Grüsse
OsDevNewbie

Ein Computer ohne Betriebsystem ist nicht mehr wert als ein Haufen Schrott.
Ein Computer ist eine Maschine, die einem Lebewesen das kostbarste klaut, was sie selber nicht hat:
DIE ZEIT DES LEBENS

 

Einloggen