From 473ff2656355a796761e9eb5e15b30cd853c58b6 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Thu, 10 Mar 2011 01:47:00 +0100 Subject: [PATCH 1/5] Fix two compile warnings when using clang Issue found by Steven Murdoch --- src/or/geoip.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/or/geoip.c b/src/or/geoip.c index e5694b9618..f3e0b72e66 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -278,6 +278,8 @@ geoip_is_loaded(void) return geoip_countries != NULL && geoip_entries != NULL; } +#define MAX_LAST_SEEN_IN_MINUTES 0x3FFFFFFFu + /** Entry in a map from IP address to the last time we've seen an incoming * connection from that IP address. Used by bridges only, to track which * countries have them blocked. */ @@ -413,12 +415,13 @@ geoip_note_client_seen(geoip_client_action_t action, lookup.ipaddr = addr; lookup.action = (int)action; ent = HT_FIND(clientmap, &client_history, &lookup); + tor_assert(now / 60 <= MAX_LAST_SEEN_IN_MINUTES); if (ent) { - ent->last_seen_in_minutes = now / 60; + ent->last_seen_in_minutes = (unsigned)(now/60); } else { ent = tor_malloc_zero(sizeof(clientmap_entry_t)); ent->ipaddr = addr; - ent->last_seen_in_minutes = now / 60; + ent->last_seen_in_minutes = (unsigned)(now/60); ent->action = (int)action; HT_INSERT(clientmap, &client_history, ent); } From 56bdc844ba68ac0911efc7ad3398f1eafeaaac76 Mon Sep 17 00:00:00 2001 From: Steven Murdoch Date: Wed, 9 Mar 2011 19:05:51 +0000 Subject: [PATCH 2/5] Fix compilation under LLVM/clang with --enable-gcc-warnings - When compiling using clang (2.9 or lower) do not enable -Wnormalized=id or -Woverride-init when --enable-gcc-warnings or --enable-gcc-warnings-advisory is set as these options are unsupported. --- configure.in | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index f30402d5b5..9999f6034b 100644 --- a/configure.in +++ b/configure.in @@ -894,6 +894,11 @@ if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xy #error #endif])], have_gcc43=yes, have_gcc43=no) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [ +#if !defined(__clang__) || (__clang_major__ > 2) || (__clang_major__ == 2 && __clang_minor__ > 9) +#error +#endif])], have_clang29orlower=yes, have_clang29orlower=no) + save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -Wshorten-64-to-32" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes, @@ -924,11 +929,19 @@ if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xy if test x$have_gcc42 = xyes ; then # These warnings break gcc 4.0.2 and work on gcc 4.2 # XXXX020 See if any of these work with earlier versions. - CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wnormalized=id -Woverride-init -Wstrict-overflow=1" + CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1" + # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3. fi - if test x$have_gcc43 = xyes ; then + if test x$have_gcc42 = xyes && test x$have_clang29orlower = xno; then + # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2 + # We only disable these for clang 2.9 and lower, in case they are + # supported in later versions. + CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init" + fi + + if test x$have_gcc43 = xyes ; then # These warnings break gcc 4.2 and work on gcc 4.3 # XXXX020 See if any of these work with earlier versions. CFLAGS="$CFLAGS -Wextra -Warray-bounds" From 547635c0049ec92e929e0f360f729b5dd308a215 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 17 Mar 2011 14:06:04 -0400 Subject: [PATCH 3/5] Futz with the clang patch a bit and tidy some geoip.c stuff --- src/or/geoip.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/or/geoip.c b/src/or/geoip.c index f3e0b72e66..a99165488a 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -278,19 +278,24 @@ geoip_is_loaded(void) return geoip_countries != NULL && geoip_entries != NULL; } -#define MAX_LAST_SEEN_IN_MINUTES 0x3FFFFFFFu - /** Entry in a map from IP address to the last time we've seen an incoming * connection from that IP address. Used by bridges only, to track which * countries have them blocked. */ typedef struct clientmap_entry_t { HT_ENTRY(clientmap_entry_t) node; uint32_t ipaddr; + /** Time when we last saw this IP address, in MINUTES since the epoch. + * + * (This will run out of space around 4011 CE. If Tor is still in use around + * 4000 CE, please remember to add more bits to last_seen_in_minutes.) */ unsigned int last_seen_in_minutes:30; unsigned int action:2; } clientmap_entry_t; -#define ACTION_MASK 3 +/** Largest allowable value for last_seen_in_minutes. (It's a 30-bit field, + * so it can hold up to (1u<<30)-1, or 0x3fffffffu. + */ +#define MAX_LAST_SEEN_IN_MINUTES 0X3FFFFFFFu /** Map from client IP address to last time seen. */ static HT_HEAD(clientmap, clientmap_entry_t) client_history = @@ -415,16 +420,16 @@ geoip_note_client_seen(geoip_client_action_t action, lookup.ipaddr = addr; lookup.action = (int)action; ent = HT_FIND(clientmap, &client_history, &lookup); - tor_assert(now / 60 <= MAX_LAST_SEEN_IN_MINUTES); - if (ent) { - ent->last_seen_in_minutes = (unsigned)(now/60); - } else { + if (! ent) { ent = tor_malloc_zero(sizeof(clientmap_entry_t)); ent->ipaddr = addr; - ent->last_seen_in_minutes = (unsigned)(now/60); ent->action = (int)action; HT_INSERT(clientmap, &client_history, ent); } + if (now / 60 <= MAX_LAST_SEEN_IN_MINUTES && now >= 0) + ent->last_seen_in_minutes = (unsigned)(now/60); + else + ent->last_seen_in_minutes = 0; if (action == GEOIP_CLIENT_NETWORKSTATUS || action == GEOIP_CLIENT_NETWORKSTATUS_V2) { From 3f94c4a1cb284ad177bbf2171d6d1c955d8baa85 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Fri, 18 Mar 2011 17:04:01 +0100 Subject: [PATCH 4/5] Remove superfluous -g -O2 compiler argument Autoconf adds -g -O2 by default, so adding it ourselves is not required. It also caused a warning with clang for every source file, so remove it here. Fixes last issue of ticket 2696. --- configure.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/configure.in b/configure.in index 9999f6034b..4436fe2075 100644 --- a/configure.in +++ b/configure.in @@ -865,12 +865,13 @@ fi # Set CFLAGS _after_ all the above checks, since our warnings are stricter # than autoconf's macros like. if test "$GCC" = yes; then - CFLAGS="$CFLAGS -Wall -g -O2" # Disable GCC's strict aliasing checks. They are an hours-to-debug # accident waiting to happen. - CFLAGS="$CFLAGS -fno-strict-aliasing" + CFLAGS="$CFLAGS -Wall -fno-strict-aliasing" else - CFLAGS="$CFLAGS -g -O" + # Autoconf sets -g -O2 by default. Override optimization level + # for non-gcc compilers + CFLAGS="$CFLAGS -O" enable_gcc_warnings=no enable_gcc_warnings_advisory=no fi From 4aac35cafa9843d10b05921da51dcc42bc3e9176 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Fri, 18 Mar 2011 17:13:43 +0100 Subject: [PATCH 5/5] Add 2696 changes file --- changes/bug2696 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changes/bug2696 diff --git a/changes/bug2696 b/changes/bug2696 new file mode 100644 index 0000000000..6ea41d4a6a --- /dev/null +++ b/changes/bug2696 @@ -0,0 +1,5 @@ + o Minor features: + - Make compilation with clang possible when using + --enable-gcc-warnings by removing two warnings that clang hasn't + implemented yet and by fixing a few warnings. Implements ticket + 2696.