syslogd,logger: code shrink for musl
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 16 Aug 2017 13:05:36 +0000 (15:05 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 16 Aug 2017 13:05:36 +0000 (15:05 +0200)
function                                             old     new   delta
syslogd_main                                        1252    1910    +658
logger_main                                          277     393    +116
timestamp_and_log                                    434     542    +108
static.__compound_literal                              -     104    +104
parse_fac_prio_20                                    137       -    -137
pencode                                              167       -    -167
parse_syslogdcfg                                     715       -    -715
------------------------------------------------------------------------------
(add/remove: 1/3 grow/shrink: 3/0 up/down: 986/-1019)         Total: -33 bytes
   text    data     bss     dec     hex filename
 912506     563    6132  919201   e06a1 busybox_old
 912364     563    6132  919059   e0613 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
sysklogd/logger.c
sysklogd/syslogd.c
sysklogd/syslogd_and_logger.c

index 359ac3acfd620bded070c0e260386f60ef0cdd53..1e0384c09e2de50e33ed3308e032aaea6ee237b5 100644 (file)
@@ -77,14 +77,14 @@ static int pencode(char *s)
                ;
        if (*s) {
                *s = '\0';
-               fac = decode(save, facilitynames);
+               fac = decode(save, bb_facilitynames);
                if (fac < 0)
                        bb_error_msg_and_die("unknown %s name: %s", "facility", save);
                *s++ = '.';
        } else {
                s = save;
        }
-       lev = decode(s, prioritynames);
+       lev = decode(s, bb_prioritynames);
        if (lev < 0)
                bb_error_msg_and_die("unknown %s name: %s", "priority", save);
        return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
index 2b85234a7d52780bd78351077a95de2f9317b247..4265f4f904eb7eb9f9ff27f2d6ea58719b9930a0 100644 (file)
@@ -447,7 +447,7 @@ static void parse_syslogdcfg(const char *file)
                                primap = 0xff; /* all 8 log levels enabled */
                        else {
                                uint8_t priority;
-                               code = find_by_name(t, prioritynames);
+                               code = find_by_name(t, bb_prioritynames);
                                if (!code)
                                        goto cfgerr;
                                primap = 0;
@@ -480,7 +480,7 @@ static void parse_syslogdcfg(const char *file)
                                        next_facility = strchr(t, ',');
                                        if (next_facility)
                                                *next_facility++ = '\0';
-                                       code = find_by_name(t, facilitynames);
+                                       code = find_by_name(t, bb_facilitynames);
                                        if (!code)
                                                goto cfgerr;
                                        /* "mark" is not a real facility, skip it */
@@ -797,9 +797,9 @@ static void parse_fac_prio_20(int pri, char *res20)
 {
        const CODE *c_pri, *c_fac;
 
-       c_fac = find_by_val(LOG_FAC(pri) << 3, facilitynames);
+       c_fac = find_by_val(LOG_FAC(pri) << 3, bb_facilitynames);
        if (c_fac) {
-               c_pri = find_by_val(LOG_PRI(pri), prioritynames);
+               c_pri = find_by_val(LOG_PRI(pri), bb_prioritynames);
                if (c_pri) {
                        snprintf(res20, 20, "%s.%s", c_fac->c_name, c_pri->c_name);
                        return;
index 6458a9332ce1f7ab76c8e9e258706686900c9bbf..6d06a718b34d6e6e774cab99f77331e0ac1b613b 100644 (file)
@@ -43,6 +43,17 @@ typedef struct _code {
  */
 #endif
 
+/* musl decided to be funny and it implements these as giant defines
+ * of the form: ((CODE *)(const CODE []){ ... })
+ * Which works, but causes _every_ function using them
+ * to have a copy on stack (at least with gcc-6.3.0).
+ * If we reference them just once, this saves 150 bytes.
+ * The pointers themselves are optimized out
+ * (no size change on uclibc).
+ */
+static const CODE *const bb_prioritynames = prioritynames;
+static const CODE *const bb_facilitynames = facilitynames;
+
 #if ENABLE_SYSLOGD
 #include "syslogd.c"
 #endif