diff options
author | Jim Huang <jserv@0xlab.org> | 2011-12-12 16:31:51 +0800 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2013-07-24 13:12:58 -0700 |
commit | e74dd8bfad25af72d07cc3a33165d3c464b6d2bd (patch) | |
tree | 695d732f57d44b681d37d10b9ac8f61111d41c26 | |
parent | d146e8e4e922aa272aa4c088fd6122836c8f45ca (diff) | |
download | bionic-e74dd8bfad25af72d07cc3a33165d3c464b6d2bd.zip bionic-e74dd8bfad25af72d07cc3a33165d3c464b6d2bd.tar.gz bionic-e74dd8bfad25af72d07cc3a33165d3c464b6d2bd.tar.bz2 |
Use GCC's __attribute__((const)) to reduce code size
__attribute__((const)) is mainly intended for the compiler to optimize
away repeated calls to a function that the compiler knows will return
the same value repeatedly.
By adding __attribute__((const)), the compiler can choose to call the
function just once and cache the return value. Therefore, this yields
code size reduction.
Here are the reference results by arm-eabi-size for crespo device:
[before]
text data bss dec hex filename
267715 10132 45948 323795 4f0d3
[after]
text data bss dec hex filename
267387 10132 45948 323467 4ef8b
Change-Id: I1d80465c0f88158449702d4dc6398a130eb77195
-rw-r--r-- | libc/include/errno.h | 1 | ||||
-rw-r--r-- | libc/include/pthread.h | 1 | ||||
-rw-r--r-- | libc/include/resolv.h | 2 |
3 files changed, 3 insertions, 1 deletions
diff --git a/libc/include/errno.h b/libc/include/errno.h index 2e5ce5f..948340d 100644 --- a/libc/include/errno.h +++ b/libc/include/errno.h @@ -41,6 +41,7 @@ __BEGIN_DECLS #endif /* internal function returning the address of the thread-specific errno */ +__attribute__((const)) extern volatile int* __errno(void); /* a macro expanding to the errno l-value */ diff --git a/libc/include/pthread.h b/libc/include/pthread.h index dbdee70..38d3400 100644 --- a/libc/include/pthread.h +++ b/libc/include/pthread.h @@ -146,6 +146,7 @@ void pthread_exit(void * retval); int pthread_join(pthread_t thid, void ** ret_val); int pthread_detach(pthread_t thid); +__attribute__((const)) pthread_t pthread_self(void); int pthread_equal(pthread_t one, pthread_t two); diff --git a/libc/include/resolv.h b/libc/include/resolv.h index 7c34012..221410d 100644 --- a/libc/include/resolv.h +++ b/libc/include/resolv.h @@ -40,7 +40,7 @@ __BEGIN_DECLS struct res_state; -extern struct __res_state *__res_state(void); +extern struct __res_state *__res_state(void) __attribute__((const)); #define _res (*__res_state()) /* Base-64 functions - because some code expects it there */ |