This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Possible weak linker bug in ld


Svein E. Seldal wrote:

>The case that I've run into is when you have a library that represents a
>  specific function for this target, like a library for, say a 
>serialport. This library is also dependent on having an ISR handler to 
>work properly.

>It would be very convenient if this library was able to override the 
>local weak symbol, and in this manner be able to automagically install 
>the ISR handler correctly.

>Now I need to distribute the library *and* the ISR handler source file 
>in two files. When linking I need to add the library and the ISR handler 
>file to be able to make it work properly.

In a similar situation I wanted to avoid the weak symbol issue (mostly because I found
it to be confusing) so what I did is to create a library that contains all the default
ISR handlers as well as the module that generated the ISR vectors (which referenced the
ISR handlers as external symbols.

Then if the application needed to override the handler, it defined the appropriately named 
symbol so that when the link was done the application symbol would resolve the reference in
the vector table and the default handler in the library wasn't used. If there was no handler
defined in the application (or even in an earlier library) then the linker would use the 
default handler from the ISR library. As long as this library was linked in last it ended up
providing any needed handlers.

This way you just need to provide a list of handler names/symbols that can be used to override
the default, and everything is in one library. The only disadvantage is that you need to have
a separate module in the library for each handler (or group of handlers) and that's just an
editing/number of source files issue, not a technical problem.

The additional advantage is that if you need to group the handlers (e.g. serial TX, rx and error) 
and the application doesn't provide all the handlers (e.g. doesn't implement serial error) then 
the linker will use the library to resolve the missing handler and warn about the duplicate
symbols for the other 2 handlers. If you document this then it can be used to identify where there
are missing handlers.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]