This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Is there a way to detect a null reference function pointer during assembly or linking ?
- From: William Tambe <tambewilliam at gmail dot com>
- To: binutils at sourceware dot org
- Date: Sat, 30 Nov 2019 08:59:29 -0500
- Subject: Re: Is there a way to detect a null reference function pointer during assembly or linking ?
- References: <CAF8i9mPL59876dxgHAM81AV7P8T4dBuQ1tOj2N=sPK8FWE3GLQ@mail.gmail.com>
To supplement my previous question, a null reference function pointer
can occur when using a weak function for which there is no definition;
ie:
extern void func (void) __attribute__((weak));
int main () {
if (func)
func();
}
In the above example, func will be null if there is no default implementation.
The issue I am running into is that the value of a null reference
function pointer is not null when the executable is not loaded at the
address specified in the ELF header, because that value is computed by
offsetting a constant value from the
start of the section .text.
I would like to be able to detect a null reference function pointer,
and generate an instruction that load a null immediate value instead
of computing the null reference function pointer value by offsetting a
constant value.
Any pointers would be much appreciated.
On Fri, Nov 29, 2019 at 9:23 PM William Tambe <tambewilliam@gmail.com> wrote:
>
> Is there a way to detect a null reference function pointer during
> assembly or linking ?
>
> In fact, the target to which I ported Binutils always generate
> position-independent-code; so it is not always loaded at the address
> specified in the ELF header, and that is where I run into issues; the
> value of a null reference function pointer is not null when the
> executable is not loaded at the address specified in the ELF header,
> because that value is computed by offsetting a constant value from the
> start of the section .text.
>
> I would like to be able to detect a null reference function pointer,
> and generate an instruction that load a null immediate value instead
> of computing the null reference function pointer value by offsetting a
> constant value.
>
> Any pointers would be much appreciated.