title: Probleme to link my stub with newlib with arm-none-eabi-gcc
body: <p>I'm trying to compile a small proof of work tath run lua code on the rasperry pi zero bare-metal.</p>
  <p>All my object file and lua's have been compiled with similar options. I tried with and without the <code>-nostdlib</code> and <code>-lc -lgcc</code> but the output is the same.</p>
  <p>Commande:</p>
  <pre><code>arm-none-eabi-gcc \
      -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s \
      -g -O0 \
      -Wl,-z,max-page-size=0x04,-T,linker.ld \
      -nostdlib \
      ./lua/lua-5.4.4/src/lapi.o ./lua/lua-5.4.4/src/lauxlib.o ./lua/lua-5.4.4/src/lbaselib.o ./lua/lua-5.4.4/src/lcode.o ./lua/lua-5.4.4/src/lcorolib.o ./lua/lua-5.4.4/src/lctype.o ./lua/lua-5.4.4/src/ldblib.o ./lua/lua-5.4.4/src/ldebug.o ./lua/lua-5.4.4/src/ldo.o ./lua/lua-5.4.4/src/ldump.o ./lua/lua-5.4.4/src/lfunc.o ./lua/lua-5.4.4/src/lgc.o ./lua/lua-5.4.4/src/linit.o ./lua/lua-5.4.4/src/liolib.o ./lua/lua-5.4.4/src/llex.o ./lua/lua-5.4.4/src/lmathlib.o ./lua/lua-5.4.4/src/lmem.o ./lua/lua-5.4.4/src/loadlib.o ./lua/lua-5.4.4/src/lobject.o ./lua/lua-5.4.4/src/lopcodes.o ./lua/lua-5.4.4/src/loslib.o ./lua/lua-5.4.4/src/lparser.o ./lua/lua-5.4.4/src/lstate.o ./lua/lua-5.4.4/src/lstring.o ./lua/lua-5.4.4/src/lstrlib.o ./lua/lua-5.4.4/src/ltable.o ./lua/lua-5.4.4/src/ltablib.o ./lua/lua-5.4.4/src/ltm.o ./lua/lua-5.4.4/src/lundump.o ./lua/lua-5.4.4/src/lutf8lib.o ./lua/lua-5.4.4/src/lvm.o ./lua/lua-5.4.4/src/lzio.o \
      ./.build/startup.o ./.build/start.o ./.build/main.o ./.build/bootstrap.lua.o ./.build/0stubs.o \
      -lc \
      -lgcc \
      -lm
  </code></pre>
  <p>Output:</p>
  <pre><code>/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-fstatr.o): in function `_fstat_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/fstatr.c:55: undefined reference to `_fstat'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-openr.o): in function `_open_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/openr.c:50: undefined reference to `_open'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-timesr.o): in function `_times_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/timesr.c:52: undefined reference to `_times'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-unlinkr.o): in function `_unlink_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/unlinkr.c:47: undefined reference to `_unlink'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-writer.o): in function `_write_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/writer.c:49: undefined reference to `_write'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-closer.o): in function `_close_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/closer.c:47: undefined reference to `_close'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-gettimeofdayr.o): in function `_gettimeofday_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/gettimeofdayr.c:62: undefined reference to `_gettimeofday'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-isattyr.o): in function `_isatty_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/isattyr.c:52: undefined reference to `_isatty'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-linkr.o): in function `_link_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/linkr.c:53: undefined reference to `_link'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-lseekr.o): in function `_lseek_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/lseekr.c:49: undefined reference to `_lseek'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-readr.o): in function `_read_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/readr.c:49: undefined reference to `_read'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-signalr.o): in function `_kill_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/signalr.c:53: undefined reference to `_kill'
  /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-signalr.o): in function `_getpid_r':
  /build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/signalr.c:83: undefined reference to `_getpid'
  </code></pre>
  <p>My 0stubs.c file:</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;sys/stat.h&gt;
  
  /* A helper function written in assembler to aid us in allocating memory */
  extern caddr_t _get_stack_pointer(void);
  
  
  /* Increase program data space. As malloc and related functions depend on this,
     it is useful to have a working implementation. The following suffices for a
     standalone system; it exploits the symbol _end automatically defined by the
     GNU linker. */
  caddr_t _sbrk( int incr )
  {
      extern char _end;
      static char* heap_end = 0;
      char* prev_heap_end;
  
      if( heap_end == 0 )
          heap_end = &amp;_end;
  
       prev_heap_end = heap_end;
  
       heap_end += incr;
       return (caddr_t)prev_heap_end;
  }
  
  int close(int file) {
    return -1;
  }
  
  char *__env[1] = { 0 };
  char **environ = __env;
  
  #include &lt;errno.h&gt;
  #undef errno
  extern int errno;
  int execve(char *name, char **argv, char **env) {
    errno = ENOMEM;
    return -1;
  }
  
  int fork(void) {
    errno = EAGAIN;
    return -1;
  }
  
  int kill(int pid, int sig) {
    errno = EINVAL;
    return -1;
  }
  
  int link(char *old, char *new) {
    errno = EMLINK;
    return -1;
  }
  
  int fstat(int file, struct stat *st) {
    st-&gt;st_mode = S_IFCHR;
    return 0;
  }
  
  int getpid(void) {
    return 1;
  }
  
  int isatty(int file) {
    return 1;
  }
  
  int lseek(int file, int ptr, int dir) {
    return 0;
  }
  
  int open(const char *name, int flags, int mode) {
    return -1;
  }
  
  int read(int file, char *ptr, int len) {
    return 0;
  }
  
  int times(struct tms *buf) {
    return -1;
  }
  
  int unlink(char *name) {
    errno = ENOENT;
    return -1; 
  }
  
  int wait(int *status) {
    errno = ECHILD;
    return -1;
  }
  
  int write(int file, char *ptr, int len) {
    int todo;
  
    for (todo = 0; todo &lt; len; todo++) {
      //outbyte (*ptr++);
    }
    return len;
  }
  
  void abort(void){
      while(1){}
  }
  
  void exit(int status){
      while(1){}
  }
  </code></pre>