From 84e5fc4775ff8e655f92d9214eac0b58a6732320 Mon Sep 17 00:00:00 2001 From: Kinjal Pravinbhai Patel Date: Wed, 9 Jul 2014 15:54:32 +0530 Subject: [PATCH] BSP: Added weak attribute into functions of BSP which are also present in tool chain This patch fixes issue of multiple definition of function in toolchain and BSP for some special cases. Signed-off-by: Kinjal Pravinbhai Patel Acked-by: Anirudha Sarangi --- lib/bsp/standalone/src/changelog.txt | 3 ++- lib/bsp/standalone/src/cortexa9/armcc/_sys_close.c | 2 +- lib/bsp/standalone/src/cortexa9/armcc/_sys_exit.c | 2 +- lib/bsp/standalone/src/cortexa9/armcc/_sys_iserror.c | 2 +- lib/bsp/standalone/src/cortexa9/armcc/_sys_istty.c | 2 +- lib/bsp/standalone/src/cortexa9/armcc/_sys_open.c | 2 +- lib/bsp/standalone/src/cortexa9/armcc/_sys_read.c | 2 +- lib/bsp/standalone/src/cortexa9/armcc/_sys_write.c | 2 +- lib/bsp/standalone/src/cortexa9/gcc/_exit.c | 2 +- lib/bsp/standalone/src/cortexa9/gcc/_open.c | 4 ++-- lib/bsp/standalone/src/cortexa9/gcc/_sbrk.c | 4 ++-- lib/bsp/standalone/src/cortexa9/gcc/abort.c | 2 +- lib/bsp/standalone/src/cortexa9/gcc/close.c | 4 ++-- lib/bsp/standalone/src/cortexa9/gcc/errno.c | 4 ++-- lib/bsp/standalone/src/cortexa9/gcc/fcntl.c | 2 +- lib/bsp/standalone/src/cortexa9/gcc/fstat.c | 4 ++-- lib/bsp/standalone/src/cortexa9/gcc/getpid.c | 6 +++--- lib/bsp/standalone/src/cortexa9/gcc/isatty.c | 6 +++--- lib/bsp/standalone/src/cortexa9/gcc/kill.c | 6 +++--- lib/bsp/standalone/src/cortexa9/gcc/lseek.c | 6 +++--- lib/bsp/standalone/src/cortexa9/gcc/open.c | 4 ++-- lib/bsp/standalone/src/cortexa9/gcc/read.c | 6 +++--- lib/bsp/standalone/src/cortexa9/gcc/sbrk.c | 4 ++-- lib/bsp/standalone/src/cortexa9/gcc/unlink.c | 4 ++-- lib/bsp/standalone/src/cortexa9/gcc/write.c | 6 +++--- 25 files changed, 46 insertions(+), 45 deletions(-) diff --git a/lib/bsp/standalone/src/changelog.txt b/lib/bsp/standalone/src/changelog.txt index b903159a..27e57d3b 100755 --- a/lib/bsp/standalone/src/changelog.txt +++ b/lib/bsp/standalone/src/changelog.txt @@ -182,5 +182,6 @@ * cortexa9/xil_exception.c to fix CR#802862. * 4.2 pkp 06/30/14 MakeFile for cortexa9/armcc has been changed to fixes the * issue of improper linking of translation_table.s - * + * 4.2 pkp 07/04/14 added weak attribute for the function in BSP which are also present + * in tool chain to avoid conflicts into some special cases *****************************************************************************************/ diff --git a/lib/bsp/standalone/src/cortexa9/armcc/_sys_close.c b/lib/bsp/standalone/src/cortexa9/armcc/_sys_close.c index c83077d9..975aedf5 100755 --- a/lib/bsp/standalone/src/cortexa9/armcc/_sys_close.c +++ b/lib/bsp/standalone/src/cortexa9/armcc/_sys_close.c @@ -1,6 +1,6 @@ // Stuv for close() sys-call -int $Sub$$_sys_close(int fh) +__weak int _sys_close(int fh) { return -1; } diff --git a/lib/bsp/standalone/src/cortexa9/armcc/_sys_exit.c b/lib/bsp/standalone/src/cortexa9/armcc/_sys_exit.c index 7fe24f34..b1235b81 100755 --- a/lib/bsp/standalone/src/cortexa9/armcc/_sys_exit.c +++ b/lib/bsp/standalone/src/cortexa9/armcc/_sys_exit.c @@ -1,6 +1,6 @@ // Stuv for exit() sys-call -void $Sub$$_sys_exit(int rc) +__weak void _sys_exit(int rc) { while(1); } diff --git a/lib/bsp/standalone/src/cortexa9/armcc/_sys_iserror.c b/lib/bsp/standalone/src/cortexa9/armcc/_sys_iserror.c index a093cd05..c6fbb978 100755 --- a/lib/bsp/standalone/src/cortexa9/armcc/_sys_iserror.c +++ b/lib/bsp/standalone/src/cortexa9/armcc/_sys_iserror.c @@ -1,6 +1,6 @@ // Stub for iserror() function -int $Sub$$_sys_iserror(int status) +__weak int _sys_iserror(int status) { if(status<0) return 1; diff --git a/lib/bsp/standalone/src/cortexa9/armcc/_sys_istty.c b/lib/bsp/standalone/src/cortexa9/armcc/_sys_istty.c index c48f2c2d..e2fa4834 100755 --- a/lib/bsp/standalone/src/cortexa9/armcc/_sys_istty.c +++ b/lib/bsp/standalone/src/cortexa9/armcc/_sys_istty.c @@ -1,6 +1,6 @@ // Stub for istty sys-call -int $Sub$$_sys_istty(unsigned int* f) +__weak int _sys_istty(unsigned int* f) { /* cannot read/write files */ return 1; diff --git a/lib/bsp/standalone/src/cortexa9/armcc/_sys_open.c b/lib/bsp/standalone/src/cortexa9/armcc/_sys_open.c index 47cb8bc7..9845f1aa 100755 --- a/lib/bsp/standalone/src/cortexa9/armcc/_sys_open.c +++ b/lib/bsp/standalone/src/cortexa9/armcc/_sys_open.c @@ -1,6 +1,6 @@ // Stub for open sys-call -int $Sub$$_sys_open(const char* name, int openmode) +__weak int _sys_open(const char* name, int openmode) { return 0; } diff --git a/lib/bsp/standalone/src/cortexa9/armcc/_sys_read.c b/lib/bsp/standalone/src/cortexa9/armcc/_sys_read.c index f328ef71..c1a5292e 100755 --- a/lib/bsp/standalone/src/cortexa9/armcc/_sys_read.c +++ b/lib/bsp/standalone/src/cortexa9/armcc/_sys_read.c @@ -1,6 +1,6 @@ // Stub for read() sys-call -int $Sub$$_sys_read(unsigned int fh, unsigned char *buf, unsigned int len, int mode) +__weak int _sys_read(unsigned int fh, unsigned char *buf, unsigned int len, int mode) { // Return the number of character NOT read return len; diff --git a/lib/bsp/standalone/src/cortexa9/armcc/_sys_write.c b/lib/bsp/standalone/src/cortexa9/armcc/_sys_write.c index 456c6bf0..33e28622 100755 --- a/lib/bsp/standalone/src/cortexa9/armcc/_sys_write.c +++ b/lib/bsp/standalone/src/cortexa9/armcc/_sys_write.c @@ -1,6 +1,6 @@ #include "xparameters.h" -int $Sub$$_sys_write(unsigned int fh, const unsigned char *buf, unsigned int len, int mode) +__weak int _sys_write(unsigned int fh, const unsigned char *buf, unsigned int len, int mode) { #ifdef STDOUT_BASEADDRESS unsigned int volatile *uart_base = (unsigned int *)STDOUT_BASEADDRESS; diff --git a/lib/bsp/standalone/src/cortexa9/gcc/_exit.c b/lib/bsp/standalone/src/cortexa9/gcc/_exit.c index 3619493f..8f75400b 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/_exit.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/_exit.c @@ -34,7 +34,7 @@ /* _exit - Simple implementation. Does not return. */ -void _exit (int status) +__attribute__((weak)) void _exit (int status) { (void)status; while (1); diff --git a/lib/bsp/standalone/src/cortexa9/gcc/_open.c b/lib/bsp/standalone/src/cortexa9/gcc/_open.c index 9f187adb..1006ce55 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/_open.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/_open.c @@ -34,7 +34,7 @@ #ifdef __cplusplus extern "C" { - int _open(const char *buf, int flags, int mode); + __attribute__((weak)) int _open(const char *buf, int flags, int mode); } #endif @@ -42,7 +42,7 @@ extern "C" { * _open -- open a file descriptor. We don't have a filesystem, so * we return an error. */ -int _open(const char *buf, int flags, int mode) +__attribute__((weak)) int _open(const char *buf, int flags, int mode) { (void)buf; (void)flags; diff --git a/lib/bsp/standalone/src/cortexa9/gcc/_sbrk.c b/lib/bsp/standalone/src/cortexa9/gcc/_sbrk.c index ecf8ca96..4a08ee7c 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/_sbrk.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/_sbrk.c @@ -37,11 +37,11 @@ extern int _heap_end; #ifdef __cplusplus extern "C" { - caddr_t _sbrk ( int incr ); + __attribute__((weak)) caddr_t _sbrk ( int incr ); } #endif -caddr_t _sbrk ( int incr ) +__attribute__((weak)) caddr_t _sbrk ( int incr ) { static unsigned char *heap = NULL; unsigned char *prev_heap; diff --git a/lib/bsp/standalone/src/cortexa9/gcc/abort.c b/lib/bsp/standalone/src/cortexa9/gcc/abort.c index 1d3f4199..377a5a85 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/abort.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/abort.c @@ -36,7 +36,7 @@ /* * abort -- go out via exit... */ -void abort(void) +__attribute__((weak)) void abort(void) { _exit(1); } diff --git a/lib/bsp/standalone/src/cortexa9/gcc/close.c b/lib/bsp/standalone/src/cortexa9/gcc/close.c index 83606b9d..f18b9cdb 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/close.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/close.c @@ -31,7 +31,7 @@ ******************************************************************************/ #ifdef __cplusplus extern "C" { - int _close(int fd); + __attribute__((weak)) int _close(int fd); } #endif @@ -39,7 +39,7 @@ extern "C" { * close -- We don't need to do anything, but pretend we did. */ -int _close(int fd) +__attribute__((weak)) int _close(int fd) { (void)fd; return (0); diff --git a/lib/bsp/standalone/src/cortexa9/gcc/errno.c b/lib/bsp/standalone/src/cortexa9/gcc/errno.c index e7cedeed..4cd96711 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/errno.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/errno.c @@ -39,11 +39,11 @@ #ifdef __cplusplus extern "C" { - int * __errno (); + __attribute__((weak)) int * __errno (); } #endif -int * +__attribute__((weak)) int * __errno () { return &_REENT->_errno; diff --git a/lib/bsp/standalone/src/cortexa9/gcc/fcntl.c b/lib/bsp/standalone/src/cortexa9/gcc/fcntl.c index 2f072fac..24d8acad 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/fcntl.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/fcntl.c @@ -36,7 +36,7 @@ * fcntl -- Manipulate a file descriptor. * We don't have a filesystem, so we do nothing. */ -int fcntl (int fd, int cmd, long arg) +__attribute__((weak)) int fcntl (int fd, int cmd, long arg) { (void)fd; (void)cmd; diff --git a/lib/bsp/standalone/src/cortexa9/gcc/fstat.c b/lib/bsp/standalone/src/cortexa9/gcc/fstat.c index 76c658c7..a9abef9c 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/fstat.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/fstat.c @@ -34,13 +34,13 @@ #ifdef __cplusplus extern "C" { - int _fstat(int fd, struct stat *buf); + __attribute__((weak)) int _fstat(int fd, struct stat *buf); } #endif /* * fstat -- Since we have no file system, we just return an error. */ -int _fstat(int fd, struct stat *buf) +__attribute__((weak)) int _fstat(int fd, struct stat *buf) { (void)fd; buf->st_mode = S_IFCHR; /* Always pretend to be a tty */ diff --git a/lib/bsp/standalone/src/cortexa9/gcc/getpid.c b/lib/bsp/standalone/src/cortexa9/gcc/getpid.c index eb126695..64dd40b5 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/getpid.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/getpid.c @@ -35,16 +35,16 @@ */ #ifdef __cplusplus extern "C" { - int _getpid(); + __attribute__((weak)) int _getpid(); } #endif -int getpid() +__attribute__((weak)) int getpid() { return 1; } -int _getpid() +__attribute__((weak)) int _getpid() { return 1; } diff --git a/lib/bsp/standalone/src/cortexa9/gcc/isatty.c b/lib/bsp/standalone/src/cortexa9/gcc/isatty.c index 5c9a805c..5eaf71fa 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/isatty.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/isatty.c @@ -33,7 +33,7 @@ #ifdef __cplusplus extern "C" { - int _isatty(int fd); + __attribute__((weak)) int _isatty(int fd); } #endif @@ -42,13 +42,13 @@ extern "C" { * returns 0 if not. Since we're hooked up to a * serial port, we'll say yes _AND return a 1. */ -int isatty(int fd) +__attribute__((weak)) int isatty(int fd) { (void)fd; return (1); } -int _isatty(int fd) +__attribute__((weak)) int _isatty(int fd) { (void)fd; return (1); diff --git a/lib/bsp/standalone/src/cortexa9/gcc/kill.c b/lib/bsp/standalone/src/cortexa9/gcc/kill.c index 61103d21..9000019a 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/kill.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/kill.c @@ -34,7 +34,7 @@ #ifdef __cplusplus extern "C" { - int _kill(int pid, int sig); + __attribute__((weak)) int _kill(int pid, int sig); } #endif @@ -42,14 +42,14 @@ extern "C" { * kill -- go out via exit... */ -int kill(int pid, int sig) +__attribute__((weak)) int kill(int pid, int sig) { if(pid == 1) _exit(sig); return 0; } -int _kill(int pid, int sig) +__attribute__((weak)) int _kill(int pid, int sig) { if(pid == 1) _exit(sig); diff --git a/lib/bsp/standalone/src/cortexa9/gcc/lseek.c b/lib/bsp/standalone/src/cortexa9/gcc/lseek.c index 2a5deb29..c90c84df 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/lseek.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/lseek.c @@ -35,13 +35,13 @@ #ifdef __cplusplus extern "C" { - off_t _lseek(int fd, off_t offset, int whence); + __attribute__((weak)) off_t _lseek(int fd, off_t offset, int whence); } #endif /* * lseek -- Since a serial port is non-seekable, we return an error. */ -off_t lseek(int fd, off_t offset, int whence) +__attribute__((weak)) off_t lseek(int fd, off_t offset, int whence) { (void)fd; (void)offset; @@ -50,7 +50,7 @@ off_t lseek(int fd, off_t offset, int whence) return ((off_t)-1); } -off_t _lseek(int fd, off_t offset, int whence) +__attribute__((weak)) off_t _lseek(int fd, off_t offset, int whence) { (void)fd; (void)offset; diff --git a/lib/bsp/standalone/src/cortexa9/gcc/open.c b/lib/bsp/standalone/src/cortexa9/gcc/open.c index 75ca7b4a..224968d6 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/open.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/open.c @@ -34,14 +34,14 @@ #ifdef __cplusplus extern "C" { - int open(const char *buf, int flags, int mode); + __attribute__((weak)) int open(const char *buf, int flags, int mode); } #endif /* * open -- open a file descriptor. We don't have a filesystem, so * we return an error. */ -int open(const char *buf, int flags, int mode) +__attribute__((weak)) int open(const char *buf, int flags, int mode) { (void)buf; (void)flags; diff --git a/lib/bsp/standalone/src/cortexa9/gcc/read.c b/lib/bsp/standalone/src/cortexa9/gcc/read.c index 70fba199..d4eae693 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/read.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/read.c @@ -38,7 +38,7 @@ #ifdef __cplusplus extern "C" { - int _read (int fd, char* buf, int nbytes); + __attribute__((weak)) int _read (int fd, char* buf, int nbytes); } #endif @@ -46,7 +46,7 @@ extern "C" { * read -- read bytes from the serial port. Ignore fd, since * we only have stdin. */ -int +__attribute__((weak)) int read (int fd, char* buf, int nbytes) { #ifdef STDIN_BASEADDRESS @@ -71,7 +71,7 @@ read (int fd, char* buf, int nbytes) #endif } -int +__attribute__((weak)) int _read (int fd, char* buf, int nbytes) { #ifdef STDIN_BASEADDRESS diff --git a/lib/bsp/standalone/src/cortexa9/gcc/sbrk.c b/lib/bsp/standalone/src/cortexa9/gcc/sbrk.c index 920a8177..7193d589 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/sbrk.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/sbrk.c @@ -33,7 +33,7 @@ #include #ifdef __cplusplus extern "C" { - char *sbrk (int nbytes); + __attribute__((weak)) char *sbrk (int nbytes); } #endif @@ -44,7 +44,7 @@ extern char HeapLimit[]; static char *heap_ptr; -char *sbrk (int nbytes) +__attribute__((weak)) char *sbrk (int nbytes) { char *base; diff --git a/lib/bsp/standalone/src/cortexa9/gcc/unlink.c b/lib/bsp/standalone/src/cortexa9/gcc/unlink.c index c2963646..ab3db626 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/unlink.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/unlink.c @@ -34,14 +34,14 @@ #ifdef __cplusplus extern "C" { - int unlink(char *path); + __attribute__((weak)) int unlink(char *path); } #endif /* * unlink -- since we have no file system, * we just return an error. */ -int unlink(char *path) +__attribute__((weak)) int unlink(char *path) { (void)path; errno = EIO; diff --git a/lib/bsp/standalone/src/cortexa9/gcc/write.c b/lib/bsp/standalone/src/cortexa9/gcc/write.c index 7885f9d2..3da52c43 100755 --- a/lib/bsp/standalone/src/cortexa9/gcc/write.c +++ b/lib/bsp/standalone/src/cortexa9/gcc/write.c @@ -38,7 +38,7 @@ #ifdef __cplusplus extern "C" { - int _write (int fd, char* buf, int nbytes); + __attribute__((weak)) int _write (int fd, char* buf, int nbytes); } #endif @@ -47,7 +47,7 @@ extern "C" { * stdout and stderr are the same. Since we have no filesystem, * open will only return an error. */ -int +__attribute__((weak)) int write (int fd, char* buf, int nbytes) { @@ -70,7 +70,7 @@ write (int fd, char* buf, int nbytes) #endif } -int +__attribute__((weak)) int _write (int fd, char* buf, int nbytes) { #ifdef STDOUT_BASEADDRESS