Bugzilla – Bug 186
Need weak linkage on memory functions to make them overridable
Last modified: 2004-02-02 12:43:56
You need to log in before you can comment on or make changes to this bug.
Some applications may choose to implement their own memory managers, thus overriding the default implementations of malloc, calloc, free, et al. Thus, we should have weak linkage on these symbols so that an application can override them with its own. This was found trying to link together bash.
Fixed: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20031215/010210.html
Please note that this will produce a warning on Mac OS X, and potentially on other systems that do not support __attribute__((weak)). Perhaps we should do something like what I made the C Writer output for weak symbols?
I concur: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20031215/010237.html
hmm. On second glance, I realize that I don't actually know what is making the *llvm* gcc print out the "attribute weak not supported" warning. I will have to look through the cfe source more thoroughly. (I thought this warning was coming from the native C compiler.) I don't have time to do it right now, but I will reopen this so that I remember to look at it.
When do you see this warning ?
I see this warning when I compile the LLVM runtime (bytecode) libraries on the Mac with Misha's patch. I assume it is an erroneous warning because the applicable backend is that of LLVM, not the Mac OS X/PPC-specific stuff, and LLVM supports weak linkage.
Ah, interesting! :) -Chris
I think what is going on is, SUPPORTS_WEAK is 0 because ASM_WEAKEN_LABEL and ASM_WEAKEN_DECL are not defined, and darwin does not include elfos.h because it uses Mach-O instead of ELF. I have not verified this completely, but it looks like the most likely scenario. My guess is that varasm.c should define SUPPORTS_WEAK to be 1 unconditionally if EMIT_LLVM.... Does this sound good Chris? (I haven't tested it.)
Ugh, yeah. It looks like SUPPORTS_WEAK and SUPPORTS_ONE_ONLY should be unconditionally set when compiling into LLVM. Maybe this should be added to llvm-out.h, like we do for ASM_OUTPUT_DEF and CRT_* -Chris
Created an attachment (id=51) [details] proposed patch (UNTESTED) You mean like this? (I don't feel like booting up the mac right now to test it but if you see anything obvious let me know, and I'll try to go ahead and test it soon.)
Yup, exactly. Let me know if that works for you and I'll "check it in". :)
The proposed patch seems to work on PowerPC/Mac OS X; I don't get the warning anymore when compiling the LLVM runtime. John, can I just go ahead and commit this to llvm-out.h?
I believe this is fine. Go ahead and commit it.
finally taken care of: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040202/011064.html