Re: [pcre-dev] [Bug 664] ABI breakage in PCRE 7.6

Αρχική Σελίδα
Delete this message
Συντάκτης: Craig Silverstein
Ημερομηνία:  
Προς: zackw
Υ/ο: pcre-dev
Αντικείμενο: Re: [pcre-dev] [Bug 664] ABI breakage in PCRE 7.6
} #if defined(__GNUC__) && __GNUC__ >= 3
} extern Arg no_arg __attribute__((
} #ifdef __MACH__
} // Mach (or at least OS X), doesn't support strong aliases, so make it
} // weak.  This is a smidge less safe in theory (conceivably, someone
} // could override this symbol in their own binary), but perfectly ok.
}                  weak,
} #endif
}                  alias(__USER_LABEL_PREFIX__
}                        "_ZN7pcrecpp2RE6no_argE")));
} #endif


I like this solution!, though it's a bit ugly. I didn't know about
__USER_LABEL_PREFIX__. Below is an alternate patch that uses this
approach, and is a smidgen safer.

craig

--cut here--

Index: pcrecpp.cc
===================================================================
--- pcrecpp.cc    (revision 327)
+++ pcrecpp.cc    (working copy)
@@ -59,11 +59,23 @@


// This is for ABI compatibility with old versions of pcre (pre-7.6),
// which defined a global no_arg variable instead of putting it in the
-// RE class. This works on GCC >= 3, at least. We could probably have
-// a more inclusive test if we ever needed it.
+// RE class. This works on GCC >= 3, at least. We could probably
+// have a more inclusive test if we ever needed it. (Note that not
+// only the __attribute__ syntax, but also __USER_LABEL_PREFIX__, are
+// gnu-specific.)
#if defined(__GNUC__) && __GNUC__ >= 3
-extern Arg no_arg __attribute__((alias("_ZN7pcrecpp2RE6no_argE")));
+#if defined(__ELF__)
+extern Arg no_arg
+ __attribute__((alias(__USER_LABEL_PREFIX__ "_ZN7pcrecpp2RE6no_argE")));
+#else
+// While we know elf supports strong aliases, not all formats do (Mach
+// doesn't, for instance). So make aliases weak by default. This is
+// a smidge less safe in theory (conceivably, someone could override
+// this symbol in their own binary), but perfectly ok in practice.
+extern Arg no_arg
+ __attribute__((weak, alias(__USER_LABEL_PREFIX__ "_ZN7pcrecpp2RE6no_argE")));
#endif
+#endif

// If a regular expression has no error, its error_ field points here
static const string empty_string;