http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51113
--- Comment #7 from Markus Trippelsdorf <markus at trippelsdorf dot de>
2011-11-15 10:03:05 UTC ---
Here is a small testcase:
% cat test.ii
extern "C"
{
typedef long unsigned int size_t;
}
extern "C"
{
static inline void *js_malloc (size_t bytes)
{
}
}
namespace std
{
typedef long unsigned int size_t;
}
extern "C++"
{
inline void *operator new (std::size_t, void *__p) throw ()
{
}
class OffTheBooks
{
public:
template < class T >
__attribute__ ((always_inline)) inline static T *new_ () {
}
template < class T, class P1, class P2, class P3, class P4 >
__attribute__ ((always_inline)) inline static T *new_
(P1 p1, P2 p2, P3 p3, P4 p4)
{
void *memory =::js_malloc (sizeof (T));
return memory ? new (memory) T (p1, p2, p3, p4) : __null;
}
};
}
enum OptionKind {
OptionKindBool, OptionKindString, OptionKindInt,
OptionKindMultiString, OptionKindInvalid
};
struct Option {
const char *longflag;
const char *help;
OptionKind kind;
char shortflag;
bool terminatesOptions;
Option (OptionKind kind, char shortflag, const char *longflag,
const char *help):longflag (longflag),
help (help),
kind (kind),
shortflag (shortflag),
terminatesOptions (false) {
}
};
struct ValuedOption:public Option {
const char *metavar;
ValuedOption (OptionKind kind, char shortflag, const char *longflag,
const char *help, const char *metavar):Option (kind,
shortflag,
longflag,
help),
metavar (metavar) {
}
virtual ~ ValuedOption () = 0;
};
struct StringOption:public ValuedOption {
const char *value;
StringOption (char shortflag, const char *longflag,
const char *help, const char *metavar)
:ValuedOption (OptionKindString, shortflag, longflag,
help, metavar), value (__null) { }
virtual ~StringOption() {}
};
class OptionParser
{
bool addStringOption (char shortflag, const char *longflag,
const char *help, const char *metavar);
};
bool
OptionParser::addStringOption (char shortflag, const char *longflag,
const char *metavar, const char *help)
{
StringOption *so =
OffTheBooks::new_ <StringOption> (shortflag, longflag, help, metavar);
}
With commit 5014df5d02d9d9 reverted:
% c++ -shared -w -o /dev/null -fPIC -fno-rtti -pthread -pipe
-fprofile-generate -O0 test.ii
%
With your patch:
% c++ -shared -w -o /dev/null -fPIC -fno-rtti -pthread -pipe
-fprofile-generate -O0 test.ii
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld:
error: /tmp/cciGbsuB.o: requires dynamic R_X86_64_PC32 reloc against
'__gcov0__ZnwmPv' which may overflow at runtime; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld:
error: /tmp/cciGbsuB.o: requires dynamic R_X86_64_PC32 reloc against
'__gcov0__ZN6OptionC2E10OptionKindcPKcS2_' which may overflow at runtime;
recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld:
error: /tmp/cciGbsuB.o: requires dynamic R_X86_64_PC32 reloc against
'__gcov0__ZN12ValuedOptionC2E10OptionKindcPKcS2_S2_' which may overflow at
runtime; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld:
error: /tmp/cciGbsuB.o: requires dynamic R_X86_64_PC32 reloc against
'__gcov0__ZN12StringOptionC2EcPKcS1_S1_' which may overflow at runtime;
recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld:
error: /tmp/cciGbsuB.o: requires dynamic R_X86_64_PC32 reloc against
'__gcov0__ZN12StringOptionD2Ev' which may overflow at runtime; recompile with
-fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld:
error: /tmp/cciGbsuB.o: requires dynamic R_X86_64_PC32 reloc against
'__gcov0__ZN12StringOptionD0Ev' which may overflow at runtime; recompile with
-fPIC
collect2: error: ld returned 1 exit status