diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-05-19 10:43:32 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-05-19 10:43:32 +0000 |
commit | 0e37af831d707494a86111755a3530b707d1035c (patch) | |
tree | 472954b39a7e9ec2c319971f028b2111f7b6f86e | |
parent | 006955556f9677ecf73aac582497f6efc47d383f (diff) | |
download | busybox-w32-0e37af831d707494a86111755a3530b707d1035c.tar.gz busybox-w32-0e37af831d707494a86111755a3530b707d1035c.tar.bz2 busybox-w32-0e37af831d707494a86111755a3530b707d1035c.zip |
- make sure not to trip enless loops when using strlen in IMA mode.
(r15000 from trunk plus preprocessor fixes plus
repair of commit message)
-rw-r--r-- | include/libbb.h | 6 | ||||
-rw-r--r-- | include/platform.h | 33 | ||||
-rw-r--r-- | libbb/xfuncs.c | 13 |
3 files changed, 16 insertions, 36 deletions
diff --git a/include/libbb.h b/include/libbb.h index 0ec332b30..01393ade2 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -387,12 +387,6 @@ int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name); | |||
387 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); | 387 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); |
388 | void reset_ino_dev_hashtable(void); | 388 | void reset_ino_dev_hashtable(void); |
389 | 389 | ||
390 | /* Stupid gcc always includes its own builtin strlen()... */ | ||
391 | extern size_t bb_strlen(const char *string); | ||
392 | #ifndef BB_STRLEN_IMPLEMENTATION | ||
393 | #define strlen(x) bb_strlen(x) | ||
394 | #endif | ||
395 | |||
396 | char *bb_xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); | 390 | char *bb_xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); |
397 | 391 | ||
398 | #define FAIL_DELAY 3 | 392 | #define FAIL_DELAY 3 |
diff --git a/include/platform.h b/include/platform.h index ea2983d30..e2f97c07d 100644 --- a/include/platform.h +++ b/include/platform.h | |||
@@ -32,40 +32,29 @@ | |||
32 | # endif | 32 | # endif |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #if 0 | ||
36 | /* Attribute __malloc__ on functions was valid as of gcc 2.96. */ | ||
37 | #ifndef ATTRIBUTE_MALLOC | ||
38 | # if __GNUC_PREREQ (2,96) | ||
39 | # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) | ||
40 | # else | ||
41 | # define ATTRIBUTE_MALLOC | ||
42 | # endif /* GNUC >= 2.96 */ | ||
43 | #endif /* ATTRIBUTE_MALLOC */ | ||
44 | #endif | ||
45 | |||
46 | #ifndef ATTRIBUTE_UNUSED | 35 | #ifndef ATTRIBUTE_UNUSED |
47 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | 36 | #define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) |
48 | #endif /* ATTRIBUTE_UNUSED */ | 37 | #endif /* ATTRIBUTE_UNUSED */ |
49 | 38 | ||
50 | #ifndef ATTRIBUTE_NORETURN | 39 | #ifndef ATTRIBUTE_NORETURN |
51 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | 40 | #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) |
52 | #endif /* ATTRIBUTE_NORETURN */ | 41 | #endif /* ATTRIBUTE_NORETURN */ |
53 | 42 | ||
54 | #ifndef ATTRIBUTE_PACKED | 43 | #ifndef ATTRIBUTE_PACKED |
55 | # define ATTRIBUTE_PACKED __attribute__ ((__packed__)) | 44 | #define ATTRIBUTE_PACKED __attribute__ ((__packed__)) |
56 | #endif /* ATTRIBUTE_PACKED */ | 45 | #endif /* ATTRIBUTE_NORETURN */ |
57 | 46 | ||
58 | #ifndef ATTRIBUTE_ALIGNED | 47 | #ifndef ATTRIBUTE_ALIGNED |
59 | # define ATTRIBUTE_ALIGNED(m) __attribute__ ((__aligned__(m))) | 48 | #define ATTRIBUTE_ALIGNED(m) __attribute__ ((__aligned__(m))) |
60 | #endif /* ATTRIBUTE_ALIGNED */ | 49 | #endif /* ATTRIBUTE_ALIGNED */ |
61 | 50 | ||
62 | /* -fwhole-program makes all symbols local. The attribute externally_visible | 51 | /* -fwhole-program makes all symbols local. The attribute externally_visible |
63 | forces a symbol global. */ | 52 | forces a symbol global. */ |
64 | #ifndef ATTRIBUTE_EXTERNALLY_VISIBLE | 53 | #ifndef ATTRIBUTE_EXTERNALLY_VISIBLE |
65 | # if __GNUC_PREREQ (4,1) | 54 | # if __GNUC_PREREQ (4,1) |
66 | # define ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((__externally_visible__)) | 55 | # define ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((__externally_visible__)) |
67 | # else | 56 | # else |
68 | # define ATTRIBUTE_EXTERNALLY_VISIBLE | 57 | # define ATTRIBUTE_EXTERNALLY_VISIBLE |
69 | # endif /* GNUC >= 4.1 */ | 58 | # endif /* GNUC >= 4.1 */ |
70 | #endif /* ATTRIBUTE_EXTERNALLY_VISIBLE */ | 59 | #endif /* ATTRIBUTE_EXTERNALLY_VISIBLE */ |
71 | 60 | ||
@@ -78,6 +67,11 @@ | |||
78 | # endif | 67 | # endif |
79 | #endif | 68 | #endif |
80 | 69 | ||
70 | #ifdef __GNUC__ | ||
71 | #define strlen(x) bb_strlen(x) | ||
72 | extern size_t bb_strlen(const char *string); | ||
73 | #endif | ||
74 | |||
81 | /* ---- Endian Detection ------------------------------------ */ | 75 | /* ---- Endian Detection ------------------------------------ */ |
82 | #ifndef __APPLE__ | 76 | #ifndef __APPLE__ |
83 | # include <byteswap.h> | 77 | # include <byteswap.h> |
@@ -86,13 +80,10 @@ | |||
86 | 80 | ||
87 | #ifdef __BIG_ENDIAN__ | 81 | #ifdef __BIG_ENDIAN__ |
88 | # define BB_BIG_ENDIAN 1 | 82 | # define BB_BIG_ENDIAN 1 |
89 | # define BB_LITTLE_ENDIAN 0 | ||
90 | #elif __BYTE_ORDER == __BIG_ENDIAN | 83 | #elif __BYTE_ORDER == __BIG_ENDIAN |
91 | # define BB_BIG_ENDIAN 1 | 84 | # define BB_BIG_ENDIAN 1 |
92 | # define BB_LITTLE_ENDIAN 0 | ||
93 | #else | 85 | #else |
94 | # define BB_BIG_ENDIAN 0 | 86 | # define BB_BIG_ENDIAN 0 |
95 | # define BB_LITTLE_ENDIAN 1 | ||
96 | #endif | 87 | #endif |
97 | 88 | ||
98 | /* ---- Networking ------------------------------------------ */ | 89 | /* ---- Networking ------------------------------------------ */ |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 9ee4fcd65..8bb75f612 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -14,16 +14,8 @@ | |||
14 | #include <stdlib.h> | 14 | #include <stdlib.h> |
15 | #include <unistd.h> | 15 | #include <unistd.h> |
16 | #include <fcntl.h> | 16 | #include <fcntl.h> |
17 | |||
18 | /* Since gcc always inlines strlen(), this saves a byte or two, but we need | ||
19 | * the #undef here to avoid endless loop from #define strlen bb_strlen */ | ||
20 | #ifdef L_strlen | ||
21 | #define BB_STRLEN_IMPLEMENTATION | ||
22 | #endif | ||
23 | |||
24 | #include "libbb.h" | 17 | #include "libbb.h" |
25 | 18 | ||
26 | |||
27 | #ifndef DMALLOC | 19 | #ifndef DMALLOC |
28 | #ifdef L_xmalloc | 20 | #ifdef L_xmalloc |
29 | void *xmalloc(size_t size) | 21 | void *xmalloc(size_t size) |
@@ -175,10 +167,13 @@ void bb_xfflush_stdout(void) | |||
175 | } | 167 | } |
176 | #endif | 168 | #endif |
177 | 169 | ||
170 | /* GCC forces inlining of strlen everywhere, which is generally a byte | ||
171 | larger than calling a function, and it's called a lot so it adds up. | ||
172 | */ | ||
178 | #ifdef L_strlen | 173 | #ifdef L_strlen |
179 | size_t bb_strlen(const char *string) | 174 | size_t bb_strlen(const char *string) |
180 | { | 175 | { |
181 | return(strlen(string)); | 176 | return(__builtin_strlen(string)); |
182 | } | 177 | } |
183 | #endif | 178 | #endif |
184 | 179 | ||