I noticed that sizes of functions in generated code change when I do simple unrelated changes. Example:
# diff -u vi_small.c vi_big.c --- vi_small.c 2006-11-22 23:35:39.000000000 +0100 +++ vi_big.c 2006-11-22 23:35:42.000000000 +0100 @@ -3414,6 +3414,8 @@ } sockaddr_inet; extern int dotted2sockaddr(const char *dotted, struct sockaddr* sp, int socklen); extern int create_and_bind_socket_ip4or6(const char *hostaddr, int port); +extern int setsockopt_reuseaddr(int fd); +extern int setsockopt_reuseaddr2(int fd); extern char *xstrdup(const char *s); extern char *xstrndup(const char *s, int n); extern char *safe_strncpy(char *dst, const char *src, size_t size); Both .c files have this simple function at the end: Byte *find_pair(Byte * p, Byte c) { Byte match, *q; int dir, level; match = ')'; level = 1; dir = 1; switch (c) { case '(': match = ')'; break; case '[': match = ']'; break; case '{': match = '}'; break; case ')': match = '('; dir = -1; break; case ']': match = '['; dir = -1; break; case '}': match = '{'; dir = -1; break; } for (q = p + dir; text <= q && q < end; q += dir) { if (*q == c) level++; if (*q == match) level--; if (level == 0) break; } if (level != 0) q = ((void *)0); return (q); } which is obviously does not depend on setsockopt_reuseaddr[2]. I made two extra copies of it, just for fun, but it happens without copies too. Okay, when I compile those: #!/bin/sh function compile() { gcc -fno-builtin-strlen -Os "$@" } compile -c -o vi_small.o vi_small.c compile -c -o vi_big.o vi_big.c nm --size-sort vi_small.o | grep find_pair nm --size-sort vi_big.o | grep find_pair I am getting: 000000a9 T find_pair (vi_small.c) 000000a9 T find_pairB 000000a9 T find_pairC 000000a9 T find_pairB (vi_big.c) 000000a9 T find_pairC 000000b9 T find_pair <--------- different?? How come gcc generates different code for identical source files? You saw the diff, it cannot matter at all... How come gcc generates different code for identical functions??? (vi_big.c:find_pairB is the same as vi_big.c:find_pair to the last byte) # gcc -v Using built-in specs. Target: i386-pc-linux-gnu Configured with: ../gcc-4.1.1.org/configure --prefix=/usr/app/gcc-4.1.1.org --exec-prefix=/usr/app/gcc-4.1.1.org --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/app/gcc-4.1.1.org/libexec --datadir=/usr/app/gcc-4.1.1.org/share --sysconfdir=/etc --sharedstatedir=/usr/app/gcc-4.1.1.org/var/com --localstatedir=/usr/app/gcc-4.1.1.org/var --libdir=/usr/lib --includedir=/usr/include --infodir=/usr/info --mandir=/usr/man --with-slibdir=/usr/app/gcc-4.1.1.org/lib --with-local-prefix=/usr/local --with-gxx-include-dir=/usr/app/gcc-4.1.1.org/include/g++-v3 --enable-languages=c,c++ --with-system-zlib --disable-nls --enable-threads=posix i386-pc-linux-gnu Thread model: posix gcc version 4.1.1 -- Summary: Generated code changes after unrelated edits in source. Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: vda dot linux at googlemail dot com GCC build triplet: i386-pc-linux-gnu GCC host triplet: i386-pc-linux-gnu GCC target triplet: i386-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29950