[444] | 1 | /* |
---|
| 2 | * RTEMS Fake crt0 |
---|
| 3 | * |
---|
| 4 | * Each RTEMS BSP provides its own crt0 and linker script. Unfortunately |
---|
| 5 | * this means that crt0 and the linker script are not available as |
---|
| 6 | * each tool is configured. Without a crt0 and linker script, some |
---|
| 7 | * targets do not successfully link "conftest.c" during the configuration |
---|
| 8 | * process. So this fake crt0.c provides all the symbols required to |
---|
| 9 | * successfully link a program. The resulting program will not run |
---|
| 10 | * but this is enough to satisfy the autoconf macro AC_PROG_CC. |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | #include <sys/lock.h> |
---|
| 14 | #include <sys/stat.h> |
---|
| 15 | #include <sys/uio.h> |
---|
| 16 | #include <reent.h> |
---|
| 17 | #include <signal.h> |
---|
| 18 | #include <time.h> |
---|
| 19 | #include <unistd.h> |
---|
| 20 | #include <machine/_arc4random.h> |
---|
| 21 | #include <machine/_libatomic.h> |
---|
| 22 | |
---|
| 23 | void rtems_provides_crt0( void ) {} /* dummy symbol so file always has one */ |
---|
| 24 | |
---|
| 25 | #define RTEMS_STUB(ret, func, body) \ |
---|
| 26 | ret rtems_stub_##func body; \ |
---|
| 27 | ret func body |
---|
| 28 | |
---|
| 29 | /* RTEMS provides some of its own routines including a Malloc family */ |
---|
| 30 | RTEMS_STUB(void *,malloc(size_t s), { return 0; }) |
---|
| 31 | RTEMS_STUB(void *,realloc(void* p, size_t s), { return 0; }) |
---|
| 32 | RTEMS_STUB(void, free(void* ptr), { }) |
---|
| 33 | RTEMS_STUB(void *, calloc(size_t s1, size_t s2), { return 0; }) |
---|
| 34 | RTEMS_STUB(int, posix_memalign(void **p, size_t si, size_t s2), { return -1; }) |
---|
| 35 | |
---|
| 36 | /* Stubs for routines from RTEMS <sys/lock.h> */ |
---|
| 37 | RTEMS_STUB(void, _Mutex_Acquire(struct _Mutex_Control *p), { }) |
---|
| 38 | RTEMS_STUB(int, _Mutex_Acquire_timed(struct _Mutex_Control *p1, const struct timespec *p2), { return -1; }) |
---|
| 39 | RTEMS_STUB(int, _Mutex_Try_Acquire(struct _Mutex_Control *p), { return -1; }) |
---|
| 40 | RTEMS_STUB(void, _Mutex_Release(struct _Mutex_Control *p), { }) |
---|
| 41 | |
---|
| 42 | RTEMS_STUB(void, _Mutex_recursive_Acquire(struct _Mutex_recursive_Control *p), { }) |
---|
| 43 | RTEMS_STUB(int, _Mutex_recursive_Acquire_timed(struct _Mutex_recursive_Control *p1, const struct timespec *p2), { return -1; }) |
---|
| 44 | RTEMS_STUB(int, _Mutex_recursive_Try_acquire(struct _Mutex_recursive_Control *p), { return -1; }) |
---|
| 45 | RTEMS_STUB(void, _Mutex_recursive_Release(struct _Mutex_recursive_Control *p), { }) |
---|
| 46 | |
---|
| 47 | RTEMS_STUB(void, _Condition_Wait(struct _Condition_Control *p1, struct _Mutex_Control *p2), { }) |
---|
| 48 | RTEMS_STUB(int, _Condition_Wait_timed(struct _Condition_Control *p1, struct _Mutex_Control *p2, const struct timespec *p3), { return -1; }) |
---|
| 49 | RTEMS_STUB(void, _Condition_Wait_recursive(struct _Condition_Control *p1, struct _Mutex_recursive_Control *p2), { }) |
---|
| 50 | RTEMS_STUB(int, _Condition_Wait_recursive_timed(struct _Condition_Control *p1, struct _Mutex_recursive_Control *p2, const struct timespec *p3), { return -1; }) |
---|
| 51 | RTEMS_STUB(void, _Condition_Signal(struct _Condition_Control *p), { }) |
---|
| 52 | RTEMS_STUB(void, _Condition_Broadcast(struct _Condition_Control *p), { }) |
---|
| 53 | |
---|
| 54 | RTEMS_STUB(void, _Semaphore_Wait(struct _Semaphore_Control *p), { }) |
---|
| 55 | RTEMS_STUB(void, _Semaphore_Post(struct _Semaphore_Control *p), { }) |
---|
| 56 | |
---|
| 57 | RTEMS_STUB(int, _Futex_Wait(struct _Futex_Control *p1, int *p2, int i), { return -1; }) |
---|
| 58 | RTEMS_STUB(int, _Futex_Wake(struct _Futex_Control *p, int i), { return -1; }) |
---|
| 59 | |
---|
| 60 | RTEMS_STUB(int, _Sched_Count(void), { return -1; }) |
---|
| 61 | RTEMS_STUB(int, _Sched_Index(void), { return -1; }) |
---|
| 62 | RTEMS_STUB(int, _Sched_Name_to_index(const char *p, size_t s), { return -1; }) |
---|
| 63 | RTEMS_STUB(int, _Sched_Processor_count(int i), { return 1; }) |
---|
| 64 | |
---|
| 65 | /* Stubs for routines from RTEMS <machine/_libatomic.h> */ |
---|
| 66 | RTEMS_STUB(__uint32_t, _Libatomic_Protect_start(void *ptr), { return 0; }); |
---|
| 67 | RTEMS_STUB(void, _Libatomic_Protect_end(void *ptr, __uint32_t isr_level), { }); |
---|
| 68 | RTEMS_STUB(void, _Libatomic_Lock_n(void *ptr, __size_t n), { }); |
---|
| 69 | RTEMS_STUB(void, _Libatomic_Unlock_n(void *ptr, __size_t n), { }); |
---|
| 70 | |
---|
| 71 | /* Stubs for routines for arc4random (from <unistd.h> and <machine/_arc4random.h> */ |
---|
| 72 | RTEMS_STUB(int, getentropy(void *ptr, __size_t n), { return -1; }); |
---|
| 73 | RTEMS_STUB(void, _arc4random_getentropy_fail(void), { }); |
---|
| 74 | |
---|
| 75 | #if defined(__GNUC__) |
---|
| 76 | /* |
---|
| 77 | * stubs for libstdc++ rtems-threads support functions from gcc/gthr-rtems.h |
---|
| 78 | */ |
---|
| 79 | int rtems_gxx_once() { return -1; } |
---|
| 80 | int rtems_gxx_key_create() { return -1; } |
---|
| 81 | int rtems_gxx_key_delete() { return -1; } |
---|
| 82 | void *rtems_gxx_getspecific() { return 0; } |
---|
| 83 | int rtems_gxx_setspecific() { return -1; } |
---|
| 84 | |
---|
| 85 | void rtems_gxx_mutex_init() { } |
---|
| 86 | int rtems_gxx_mutex_lock() { return -1; } |
---|
| 87 | int rtems_gxx_mutex_trylock() { return -1; } |
---|
| 88 | int rtems_gxx_mutex_unlock() { return -1; } |
---|
| 89 | |
---|
| 90 | void rtems_gxx_recursive_mutex_init() { } |
---|
| 91 | int rtems_gxx_recursive_mutex_lock() { return -1; } |
---|
| 92 | int rtems_gxx_recursive_mutex_trylock() { return -1; } |
---|
| 93 | int rtems_gxx_recursive_mutex_unlock() { return -1; } |
---|
| 94 | #endif |
---|
| 95 | |
---|
| 96 | /* stubs for functions RTEMS provides */ |
---|
| 97 | RTEMS_STUB(int, access(const char *pathname, int mode), { return -1; }) |
---|
| 98 | RTEMS_STUB(int, clock_gettime(clockid_t clk_id, struct timespec *tp), { return -1; }) |
---|
| 99 | RTEMS_STUB(int, close (int fd), { return -1; }) |
---|
| 100 | RTEMS_STUB(int, dup2(int oldfd, int newfd), { return -1; }) |
---|
| 101 | RTEMS_STUB(int, fchmod(int fd, mode_t mode ), { return -1; }) |
---|
| 102 | RTEMS_STUB(int, fcntl( int fd, int cmd, ... /* arg */ ), { return -1; }) |
---|
| 103 | RTEMS_STUB(pid_t, fork(void), { return -1; }) |
---|
| 104 | RTEMS_STUB(int, fstat(int fd, struct stat *buf), { return -1; }) |
---|
| 105 | RTEMS_STUB(int, getdents(int fd, void *dp, int count), { return -1; }) |
---|
| 106 | RTEMS_STUB(char *, getlogin(void), { return 0; }) |
---|
| 107 | RTEMS_STUB(int, gettimeofday(struct timeval *__restrict tv, struct timezone *__restrict tz), { return -1; }) |
---|
| 108 | RTEMS_STUB(struct passwd *, getpwnam(const char *name), { return 0; }) |
---|
| 109 | RTEMS_STUB(struct passwd *, getpwuid(uid_t uid), { return 0; }) |
---|
| 110 | RTEMS_STUB(uid_t, getuid(void), { return 0; }) |
---|
| 111 | RTEMS_STUB(int, nanosleep(const struct timespec *req, struct timespec *rem), { return -1; }) |
---|
| 112 | RTEMS_STUB(int, ftruncate(int fd, off_t length), { return -1; }) |
---|
| 113 | RTEMS_STUB(_off_t, lseek(int fd, _off_t offset, int whence), { return -1; }) |
---|
| 114 | RTEMS_STUB(int, lstat(const char *path, struct stat *buf), { return -1; }) |
---|
| 115 | RTEMS_STUB(int, open(const char *pathname, int flags, int mode), { return -1; }) |
---|
| 116 | RTEMS_STUB(int, pipe(int pipefd[2]), { return -1; }) |
---|
| 117 | RTEMS_STUB(_ssize_t, read(int fd, void *buf, size_t count), { return -1; }) |
---|
| 118 | RTEMS_STUB(ssize_t, readv (int fd, const struct iovec *iov, int iovcnt), { return -1; }) |
---|
| 119 | RTEMS_STUB(int, sched_yield(void), { return -1; }) |
---|
| 120 | RTEMS_STUB(int, sigfillset(sigset_t *set), { return -1; }) |
---|
| 121 | RTEMS_STUB(int, sigprocmask(int how, const sigset_t *set, sigset_t *oldset), { return -1; }) |
---|
| 122 | RTEMS_STUB(int, stat(const char *path, struct stat *buf), { return -1; }) |
---|
| 123 | RTEMS_STUB(long, sysconf(int name), { return -1; }) |
---|
| 124 | RTEMS_STUB(int, unlink(const char *pathname), { return -1; }) |
---|
| 125 | RTEMS_STUB(pid_t, vfork(void), { return -1; }) |
---|
| 126 | #if !defined(_NO_POPEN) && !defined(_NO_WORDEXP) |
---|
| 127 | /* pulled in by libc/sys/posix/popen.c and libc/sys/posix/word*.c */ |
---|
| 128 | RTEMS_STUB(int, waitpid (pid_t pid, int *status, int options), { return -1; }) |
---|
| 129 | #endif |
---|
| 130 | RTEMS_STUB(_ssize_t, write (int fd, const void *buf, size_t nbytes), { return -1; }) |
---|
| 131 | RTEMS_STUB(ssize_t, writev (int fd, const struct iovec *iov, int iovcnt), { return -1; }) |
---|
| 132 | |
---|
| 133 | /* stubs for functions from reent.h */ |
---|
| 134 | RTEMS_STUB(int, _close_r (struct _reent *r, int fd), { return -1; }) |
---|
| 135 | #if defined(_NO_EXECVE) |
---|
| 136 | RTEMS_STUB(int, _execve_r (struct _reent *r, char *, char **, char **), { return -1; }) |
---|
| 137 | #endif |
---|
| 138 | RTEMS_STUB(int, _fcntl_r (struct _reent *ptr, int fd, int cmd, int arg ), { return -1; }) |
---|
| 139 | #if !(defined (REENTRANT_SYSCALLS_PROVIDED) || defined (NO_EXEC)) |
---|
| 140 | #ifndef NO_FORK |
---|
| 141 | /* cf. newlib/libc/reent/execr.c */ |
---|
| 142 | RTEMS_STUB(int, _fork_r (struct _reent *r), { return -1; }) |
---|
| 143 | #endif |
---|
| 144 | #endif |
---|
| 145 | RTEMS_STUB(int, _fstat_r (struct _reent *r, int fd, struct stat *buf), { return -1; }) |
---|
| 146 | RTEMS_STUB(uid_t, geteuid (), { return -1; }) |
---|
| 147 | RTEMS_STUB(gid_t, getgid (), { return -1; }) |
---|
| 148 | RTEMS_STUB(gid_t, _getgid_r (struct _reent *r), { return -1; }) |
---|
| 149 | RTEMS_STUB(struct _reent *, __getreent (void), { return 0; }) |
---|
| 150 | RTEMS_STUB(pid_t, getpid (), { return -1; }) |
---|
| 151 | RTEMS_STUB(pid_t, getppid (), { return -1; }) |
---|
| 152 | RTEMS_STUB(pid_t, _getpid_r (struct _reent *r), { return -1; }) |
---|
| 153 | RTEMS_STUB(int, _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp), { return 0; }) |
---|
| 154 | RTEMS_STUB(int, _isatty_r (struct _reent *r, int fd), { return isatty( fd ); }) |
---|
| 155 | RTEMS_STUB(int, _kill_r (struct _reent *r, int pid, int sig ), { return -1; }) |
---|
| 156 | #if !defined(REENTRANT_SYSCALLS_PROVIDED) |
---|
| 157 | /* cf. newlib/libc/reent/linkr.c */ |
---|
| 158 | RTEMS_STUB(int, _link_r (struct _reent *r, const char *oldpath, const char *newpath), { return -1; }) |
---|
| 159 | #endif |
---|
| 160 | RTEMS_STUB(_off_t, _lseek_r ( struct _reent *ptr, int fd, _off_t offset, int whence ), { return -1; }) |
---|
| 161 | RTEMS_STUB(int, _open_r (struct _reent *r, const char *buf, int flags, int mode), { return -1; }) |
---|
| 162 | RTEMS_STUB(_ssize_t, _read_r (struct _reent *r, int fd, void *buf, size_t nbytes), { return -1; }) |
---|
| 163 | RTEMS_STUB(int, _rename_r (struct _reent *r, const char *a, const char *b), { return -1; }) |
---|
| 164 | #if !(defined (REENTRANT_SYSCALLS_PROVIDED) || defined (MALLOC_PROVIDED)) |
---|
| 165 | /* cf. newlib/libc/reent/sbrkr.c */ |
---|
| 166 | RTEMS_STUB(void *,_sbrk_r (struct _reent *r, ptrdiff_t addr), { return 0; }) |
---|
| 167 | #endif |
---|
| 168 | RTEMS_STUB(int, _stat_r (struct _reent *r, const char *path, struct stat *buf), { return -1; }) |
---|
| 169 | RTEMS_STUB(_CLOCK_T_, _times_r (struct _reent *r, struct tms *ptms), { return -1; }) |
---|
| 170 | RTEMS_STUB(int, _unlink_r (struct _reent *r, const char *path), { return -1; }) |
---|
| 171 | #if !(defined (REENTRANT_SYSCALLS_PROVIDED) || defined (NO_EXEC)) |
---|
| 172 | /* cf. newlib/libc/reent/execr.c */ |
---|
| 173 | RTEMS_STUB(int, _wait_r (struct _reent *r, int *status), { return -1; }) |
---|
| 174 | #endif |
---|
| 175 | RTEMS_STUB(_ssize_t, _write_r (struct _reent *r, int fd, const void *buf, size_t nbytes), { return -1; }) |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | RTEMS_STUB(int, _execve(const char *path, char * const *argv, char * const *envp), { return -1; }) |
---|
| 179 | RTEMS_STUB(void, _exit(int status), { while(1); }) |
---|
| 180 | |
---|
| 181 | /* Pulled in by newlib/libc/posix/glob.c */ |
---|
| 182 | #ifndef _NO_GLOB |
---|
| 183 | #ifndef __NETBSD_SYSCALLS |
---|
| 184 | RTEMS_STUB(int, issetugid (void), { return 0; }) |
---|
| 185 | #endif |
---|
| 186 | #endif |
---|
| 187 | |
---|
| 188 | /* stdlib.h */ |
---|
| 189 | RTEMS_STUB(void *, _realloc_r(struct _reent *r, void *p, size_t s), { return 0; }) |
---|
| 190 | RTEMS_STUB(void *, _calloc_r(struct _reent *r, size_t s1, size_t s2), { return 0; }) |
---|
| 191 | RTEMS_STUB(void *, _malloc_r(struct _reent * r, size_t s), { return 0; }) |
---|
| 192 | RTEMS_STUB(void, _free_r(struct _reent *r, void **p), { }) |
---|
| 193 | |
---|
| 194 | /* stubs for functions required by libc/stdlib */ |
---|
| 195 | RTEMS_STUB(void, __assert_func(const char *file, int line, const char *failedexpr), { }) |
---|
| 196 | |
---|
| 197 | #if defined(__arm__) |
---|
| 198 | RTEMS_STUB(void, __aeabi_read_tp(void), { }) |
---|
| 199 | RTEMS_STUB(void *, __tls_get_addr(const void *ti), { }) |
---|
| 200 | #endif |
---|
| 201 | |
---|
| 202 | /* The PowerPC expects certain symbols to be defined in the linker script. */ |
---|
| 203 | |
---|
| 204 | #if defined(__PPC__) |
---|
| 205 | int __SDATA_START__; int __SDATA2_START__; |
---|
| 206 | int __GOT_START__; int __GOT_END__; |
---|
| 207 | int __GOT2_START__; int __GOT2_END__; |
---|
| 208 | int __SBSS_END__; int __SBSS2_END__; |
---|
| 209 | int __FIXUP_START__; int __FIXUP_END__; |
---|
| 210 | int __EXCEPT_START__; int __EXCEPT_END__; |
---|
| 211 | int __init; int __fini; |
---|
| 212 | int __CTOR_LIST__; int __CTOR_END__; |
---|
| 213 | int __DTOR_LIST__; int __DTOR_END__; |
---|
| 214 | #endif |
---|
| 215 | |
---|
| 216 | /* The SH expects certain symbols to be defined in the linker script. */ |
---|
| 217 | |
---|
| 218 | #if defined(__sh__) |
---|
| 219 | int __EH_FRAME_BEGIN__; |
---|
| 220 | #endif |
---|
| 221 | |
---|
| 222 | #if defined(__AVR__) |
---|
| 223 | /* |
---|
| 224 | * Initial stack pointer address "__stack" |
---|
| 225 | * hard coded into GCC instead of providing it through ldscripts |
---|
| 226 | */ |
---|
| 227 | const char* __stack ; |
---|
| 228 | #endif |
---|