Bug 30769

Summary: [gcc/unix] Export WTF::fastMalloc, WTF::fastFree, WTF::fastCalloc, WTF::fastRealloc
Product: WebKit Reporter: Holger Freyther <zecke>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: darin
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Attachments:
Description Flags
First attempt to export these symbols
none
Export the symbols in libwebkit.so as well
darin: review+
Export fastMalloc, fastFree, fastRealloc, fastCalloc with normal linkage darin: review+

Description Holger Freyther 2009-10-26 04:30:16 PDT
All non darwin gcc targets build JSC with -fvisibility=hidden hiding the FastMalloc functions. For malloc analysis it is handy to be able to preload an instrumented version of the above functions. 

The proposed change is to use __attribute__((visibility("default"))) on GCC systems.
Comment 1 Holger Freyther 2009-10-26 04:38:17 PDT
Created attachment 41859 [details]
First attempt to export these symbols

Use __attribute__((visibility("default"))) to export the allocation functions again. On Mac these symbols are exported via the .exp file and available to the WebCore/WebKit library.
Comment 2 Holger Freyther 2009-10-26 07:08:41 PDT
Created attachment 41865 [details]
Export the symbols in libwebkit.so as well

Export the FastMalloc functions in the .so file as well. This is the last step to be able to instrument a TCmalloc enabled libwebkit with memprof.
Comment 3 Darin Adler 2009-10-26 07:49:15 PDT
Comment on attachment 41859 [details]
First attempt to export these symbols

> +#if COMPILER(GCC) && !PLATFORM(DARWIN)
> +#define WTF_FAST_MALLOC_EXPORT __attribute__((visibility("default")))
> +#else
> +#define WTF_FAST_MALLOC_EXPORT
> +#endif

Why ~PLATFORM(DARWIN)"?

If you are using __attribute__ then you should also use __visibility__.

Is it really helpful to do this just for these functions? Doesn't this need to be done consistently across the rest of JavaScriptCore?
Comment 4 Darin Adler 2009-10-26 07:50:14 PDT
Oh, I see now. You're saying this is good "for malloc analysis".

Still, why the !PLATFORM(DARWIN) part? Would this change cause a problem on that platform?
Comment 5 Holger Freyther 2009-10-26 08:00:31 PDT
(In reply to comment #4)
> Oh, I see now. You're saying this is good "for malloc analysis".

Ironically I'm working/using a tool that went from Corel -> Eazel -> GNOME into my hands. I'm using LD_PRELOAD to load my version of malloc and this fails with a release build of WebKit. One option would have been to instrument the mmap/sbrk calls but then I just see calls to TCSystem_Alloc.

> Still, why the !PLATFORM(DARWIN) part? Would this change cause a problem on
> that platform?

My assumption is that it is going to work as visibility should be okay with any gcc4.x release. On a mac build these symbols should have "default" visibility and saying they are default should be harmles. I just tried to minimize the risk of breaking a build on a file that is included by almost everything.
Comment 6 Holger Freyther 2009-10-26 08:01:46 PDT
I'm going to build on Leopard tomorrow and will send an updated patch without the !PLATFORM(DARWIN)
Comment 7 Holger Freyther 2009-10-27 06:04:37 PDT
Created attachment 41945 [details]
Export fastMalloc, fastFree, fastRealloc, fastCalloc with normal linkage

The leopard build was fine, removing the !PLATFORM(DARWIN).
Comment 8 Darin Adler 2009-10-27 10:12:41 PDT
Comment on attachment 41865 [details]
Export the symbols in libwebkit.so as well

rs=me
Comment 9 Holger Freyther 2009-10-28 03:35:55 PDT
Landed in r50204 and r50205.