> clang++ -o v8linkfail -std=c++11 -stdlib=libc++ -Wall -Werror -O0 -fno-inline -g -Wall -Werror -O0 -fno-inline -g -I/Users/scott/v8/v8/include v8linkfail.cpp -L/Users/scott/v8/v8/out.gn/x64.debug/ -lv8 -lv8_libplatform -lv8_libbase -licuuc -licui18n -lv8_for_testing
Undefined symbols for architecture x86_64:
"typeinfo for v8::ArrayBuffer::Allocator", referenced from:
typeinfo for DefaultV8ArrayBufferAllocator in v8linkfail-fbc69e.o
Here /Users/scott/v8 contains a v8 distribution checked out and built (https://github.com/v8/v8/wiki/Building-with-GN)just yesterday, and v8linkfail.cpp is a very simple test program:
/////////////////////// begin v8linkfail.cpp
#include <stdlib.h>
#include <v8.h>
class DefaultV8ArrayBufferAllocator: public v8::ArrayBuffer::Allocator {
public:
virtual void* Allocate(size_t length) {
void* data = AllocateUninitialized(length);
return data == NULL ? data : memset(data, 0, length);
}
virtual void* AllocateUninitialized(size_t length) {
return malloc(length);
}
virtual void Free(void* data, size_t) {
free(data);
}
};
int main(int argc, char** argv) {
std::unique_ptr<v8::ArrayBuffer::Allocator> alloc
(new DefaultV8ArrayBufferAllocator);
return 0;
}
> nm -mo v8linkfail_v8_5.5.o | c++filt | grep type | grep Allocator
v8linkfail_v8_5.5.o: 0000000000000450 (__DATA,__data) weak external typeinfo for DefaultV8ArrayBufferAllocator
v8linkfail_v8_5.5.o: 0000000000000438 (__DATA,__data) weak external typeinfo for v8::ArrayBuffer::Allocator
v8linkfail_v8_5.5.o: 00000000000004a0 (__TEXT,__const) weak external typeinfo name for DefaultV8ArrayBufferAllocator
v8linkfail_v8_5.5.o: 00000000000004c0 (__TEXT,__const) weak external typeinfo name for v8::ArrayBuffer::Allocator
(Note: this is not exactly where I was expecting the typeinfo to show up -- I would have expected it in v8's api.o instead of my code's object file. However, nm sees no mention of it in *either* the 5.5 or 6.1 version of api.o, so I'm going to assume that this is somehow "normal" C++ behavior.)
On the other hand, when v8linkfail.cpp is compiled to an object file using the include files in v8 6.1.0, the type info for ArrayBuffer::Allocator becomes undefined, and that's when the link errors show up:
> nm -mo v8linkfail_v8_6.1.o | c++filt | grep type | grep Allocator
v8linkfail_v8_6.1.o: 0000000000000400 (__DATA,__data) weak external typeinfo for DefaultV8ArrayBufferAllocator
v8linkfail_v8_6.1.o: (undefined) external typeinfo for v8::ArrayBuffer::Allocator
v8linkfail_v8_6.1.o: 0000000000000420 (__TEXT,__const) weak external typeinfo name for DefaultV8ArrayBufferAllocator
I'll admit I'm at a bit of a loss as to what's going on here, or how to proceed. Is there a subtle bug somewhere either in v8's code (presumably v8.h and/or api.cc) and/or in my definition of DefaultV8ArrayBufferAllocator above? (By now I've stared at both my code and v8's code to find this unlikely, but I could be missing something.) Or is there a bug somewhere in the compiling/linking toolchain (yikes)? Or is something funny going on because v8 was compiled with different tools or flags than v8linkfail.cpp? If it might be the last of these (compiled with different tools/flags), how might I go about determining exactly what tools and flags all the bits of v8 were built with, and what flags should I be suspicious of? (Building v8 with GN was not particularly transparent...is there an easy way to pass in some sort of "-v"-like flag to ninja or whatever that will dump all the commands used during the build while it's building?)
Thanks,
-- Scott