Author Topic: How to Remove Newlib Syscalls?  (Read 6700 times)

0 Members and 1 Guest are viewing this topic.

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
How to Remove Newlib Syscalls?
« on: November 21, 2012, 06:42:28 pm »
After ~half a year, I'm back :)

I'm trying to port GMP to the Nspire again. I think the library will work fine, but I'm having some problems with newlib, which is supplying its own syscalls that interfere with the ones included with Ndless. Here are the compiler errors:
Code: [Select]
nspire-ld hello.o -o helloworld.elf -L /home/philip/gmp/prefix/lib -lgmp
/home/philip/toolchain/lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/libc.a(lib_a-syscalls.o): In function `_exit':
/home/philip/toolchain/build/arm-none-eabi/newlib/libc/sys/arm/../../../../../../newlib-1.20.0/newlib/libc/sys/arm/syscalls.c:459: multiple definition of `_exit'
/home/philip/NdlessSDK/ndless/bin/../system/osstub.o:osstub.c:(.text+0x88): first defined here
/home/philip/toolchain/lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/libc.a(lib_a-syscalls.o): In function `_sbrk':
syscalls.c:(.text+0x6a8): undefined reference to `end'
collect2: error: ld returned 1 exit status
make: *** [helloworld.tns] Error 1

Are there any compiler flags to disable the newlib syscalls? And what is the cause of the second error?
And by the way, I never knew the toolchain was so big!! 1.3 GB?

Are you wondering who Sammy is? My avatar is Sammy.
   

Offline ExtendeD

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 825
  • Rating: +167/-2
    • View Profile
Re: How to Remove Newlib Syscalls?
« Reply #1 on: November 24, 2012, 08:07:04 am »
Try to add the GCC switch -nostdlib to your Makefile.
Maybe Newlib 1.20 has changed several things now incompatible with Ndless (Ndless should be compatible with Newlib 1.19).
Ndless.me with the finest TI-Nspire programs

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
Re: How to Remove Newlib Syscalls?
« Reply #2 on: November 24, 2012, 10:34:42 am »
The problem with using -nostdlib is that some library is supplying code for the basic functions like malloc and realloc, so with -nostdlib, I get huge amounts of errors about undefined references to functions:
Code: [Select]
nspire-ld hello.o -o helloworld.elf -L /home/philip/gmp/prefix/lib -lgmp -nostdlib
/home/philip/gmp/prefix/lib/libgmp.a(memory.o): In function `__gmp_default_free':
memory.c:(.text+0x4): undefined reference to `free'
/home/philip/gmp/prefix/lib/libgmp.a(memory.o): In function `__gmp_default_reallocate':
memory.c:(.text+0x20): undefined reference to `realloc'
memory.c:(.text+0x4c): undefined reference to `fprintf'
memory.c:(.text+0x50): undefined reference to `abort'
memory.c:(.text+0x54): undefined reference to `_impure_ptr'
/home/philip/gmp/prefix/lib/libgmp.a(memory.o): In function `__gmp_default_allocate':
memory.c:(.text+0x64): undefined reference to `malloc'
memory.c:(.text+0x8c): undefined reference to `fprintf'
memory.c:(.text+0x90): undefined reference to `abort'
memory.c:(.text+0x94): undefined reference to `_impure_ptr'
/home/philip/NdlessSDK/ndless/bin/../lib/libndls.a(touchpad.o): In function `touchpad_scan':
touchpad.c:(.text+0x18c): undefined reference to `__aeabi_idiv'
touchpad.c:(.text+0x1a8): undefined reference to `__aeabi_idiv'
touchpad.c:(.text+0x1c4): undefined reference to `__aeabi_idiv'
touchpad.c:(.text+0x1e0): undefined reference to `__aeabi_idiv'
touchpad.c:(.text+0x1fc): undefined reference to `__aeabi_idiv'
/home/philip/NdlessSDK/ndless/bin/../lib/libndls.a(touchpad.o):touchpad.c:(.text+0x214): more undefined references to `__aeabi_idiv' follow
collect2: error: ld returned 1 exit status
make: *** [helloworld.tns] Error 1
I looked online and they said I needed to link libgcc.a and everything would work. Is that true? I looked in the Ndless syscalls.h and it seemed to me like those functions could be found in there too.

Are you wondering who Sammy is? My avatar is Sammy.
   

Offline sammyMaX

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 204
  • Rating: +9/-0
    • View Profile
Re: How to Remove Newlib Syscalls?
« Reply #3 on: November 26, 2012, 04:20:20 pm »
I tried compiling GMP using the libndls and -nostdlib but libndls doesn't have all the functions GMP needs. It asks for a strnlen, but libndls doesn't include one. Is there any easy way to add that to the Ndless library?

EDIT: I tried making my own strnlen.c and put it in the libndls source folder and compiled it to get a new .a library. I also updated the libndls.h to include the function, but when I compile GMP, it gives me the same error. I have a feeling that it isn't detecting the new function. Any suggestions?
« Last Edit: November 26, 2012, 06:26:10 pm by sammyMaX »

Are you wondering who Sammy is? My avatar is Sammy.
   

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: How to Remove Newlib Syscalls?
« Reply #4 on: December 31, 2012, 10:06:11 am »
I compiled newlib 1.19, same error :(
Any suggestions?
I'm not very familiar with gcc and ld..

Edit: Works with Makefile.tpl. Without -nostdlib it's ~100 KB larger
Edit 2:
Code: [Select]
ld cpuops.o cpuexec.o sa1cpu.o nspire.o apudebug.o c4.o c4emu.o cpu.o sa1.o debug.o sdd1.o tile.o srtc.o gfx.o memmap.o clip.o dsp1.o ppu.o dma.o snes9x.o data.o globals.o spc7110.o obc1.o seta.o seta010.o seta011.o seta018.o fxinst.o fxemu.o fxdbg.o cheats.o cheats2.o apu.o soundux.o spc700.o -o snes9x.elf -lm
make: *** [snes9x.tns] Segmentation fault
Congratulations, binutils. *clap clap clap*
(I know I'm using the wrong one, but there should at least be an error message..)

Edit3: Edited ldscript and osstub.c, compiles now.
« Last Edit: December 31, 2012, 05:42:55 pm by Vogtinator »