Fri Mar 25 18:13:59 GMT 2005
> With your example, I get prog1 returning 0 and prog2 returning a non-NULL
> address. Is that what you expected? I can see how you could get some
> usefulness out of that.
Yup, that's the expected behaior. The prog1 example is when the target
doesn't get pulled in (prints 0) and the prog2 example is when
the target does get pulled by a proper reference in the program.
> The bothersome part in my view is that the bind=WEAK still is tied to the
> symbol and not the individual reference (or relocation, to be more precise).
> So, within a single object, you can't emit one reference for the Dwarf and
> say it's weak, and then another as part of code generation (e.g. for a call),
> and say it's strong.
Yes! It would be a better design and much easier to understand if
"weak" was a flag on the relocation record. But there isn't room
in the ELF relocation record format for any flags. You would
have to make a major new revision of ELF, or else create new
basic relocation types for weak variants of all the regular relocations
you wanted to use with weak. Yucko. So I can understand why they
did it the way they did.
> But I suppose you still can get it to work. You'll just have to keep track
> of all the references you emit in the assembly, and if only emit the weak
> directive if all of the references are for weak purposes (e.g. Dwarf
> references), and avoid it if any are strong (e.g. a call, assuming there's no
> #pragma weak in the user source).
Yes, that's exactly what you have to do.
The compiler normally does some things like this when it processes
#pragma weak definitions, but I think I'll have to teach it a
few new tricks to make this work.
> Was this your plan? If so, it seems like a decent plan to me.
Yes, that's my plan.
More information about the Dwarf-discuss