Getting build ID

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting build ID

Mark Morgan Lloyd-5
If a program is linked with GNU ld using the --build-id option, how can
it retrieve the value at runtime?

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting build ID

Andrew Haines
On 10/22/2015 08:08 PM, Mark Morgan Lloyd wrote:
> If a program is linked with GNU ld using the --build-id option, how
> can it retrieve the value at runtime?

I've never done it but maybe a place to start is use the elfreader unit
in fcl-res to open ParamStr(0) and read the data from the
.note.gnu.build-id section.

Regards,

Andrew Haines

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting build ID

Mark Morgan Lloyd-5
Andrew Haines wrote:
> On 10/22/2015 08:08 PM, Mark Morgan Lloyd wrote:
>> If a program is linked with GNU ld using the --build-id option, how
>> can it retrieve the value at runtime?
>
> I've never done it but maybe a place to start is use the elfreader unit
> in fcl-res to open ParamStr(0) and read the data from the
> .note.gnu.build-id section.

Thanks, I'll take a look. I'm looking for something that I can put as a
"magic number" at the bottom of some shared memory, and the build-id is
ideal since it can be set to a fixed value during debugging.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting build ID

Mark Morgan Lloyd-5
Mark Morgan Lloyd wrote:

> Andrew Haines wrote:
>> On 10/22/2015 08:08 PM, Mark Morgan Lloyd wrote:
>>> If a program is linked with GNU ld using the --build-id option, how
>>> can it retrieve the value at runtime?
>>
>> I've never done it but maybe a place to start is use the elfreader
>> unit in fcl-res to open ParamStr(0) and read the data from the
>> .note.gnu.build-id section.
>
> Thanks, I'll take a look. I'm looking for something that I can put as a
> "magic number" at the bottom of some shared memory, and the build-id is
> ideal since it can be set to a fixed value during debugging.

If I'm reading things properly I have to reimplement
TElfResourceReader.Load so I can get a subreader, call the FindSection
method to get a section index, then do something... I've not worked this
out yet and would appreciate any hints... to convert the section index
into an address/length in the file and read the data.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Getting build ID

Andrew Haines
On 10/25/2015 03:25 PM, Mark Morgan Lloyd wrote:

> Mark Morgan Lloyd wrote:
>> Andrew Haines wrote:
>>> On 10/22/2015 08:08 PM, Mark Morgan Lloyd wrote:
>>>> If a program is linked with GNU ld using the --build-id option, how
>>>> can it retrieve the value at runtime?
>>>
>>> I've never done it but maybe a place to start is use the elfreader
>>> unit in fcl-res to open ParamStr(0) and read the data from the
>>> .note.gnu.build-id section.
>>
>> Thanks, I'll take a look. I'm looking for something that I can put as
>> a "magic number" at the bottom of some shared memory, and the
>> build-id is ideal since it can be set to a fixed value during debugging.
>
> If I'm reading things properly I have to reimplement
> TElfResourceReader.Load so I can get a subreader, call the FindSection
> method to get a section index, then do something... I've not worked
> this out yet and would appreciate any hints... to convert the section
> index into an address/length in the file and read the data.
>
OK, I looked a bit closer at that unit and I don't think you can use it
since it's only interested in reading resource information. The
subreaders are more interesting but they are private classes that we
have no access to.

I had some time and this was interesting so I made a really basic unit
and test program to read the build id of an elf file. It's not complete
but it can read 64 bit elf files. If you need 32 it would be easy to
add. You may use the source however you want.

Regards,

Andrew Haines

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

elf_build_id.tar.gz (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Getting build ID

Mark Morgan Lloyd-5
In reply to this post by Mark Morgan Lloyd-5
Mark Morgan Lloyd wrote:

> Mark Morgan Lloyd wrote:
>> Andrew Haines wrote:
>>> On 10/22/2015 08:08 PM, Mark Morgan Lloyd wrote:
>>>> If a program is linked with GNU ld using the --build-id option, how
>>>> can it retrieve the value at runtime?
>>>
>>> I've never done it but maybe a place to start is use the elfreader
>>> unit in fcl-res to open ParamStr(0) and read the data from the
>>> .note.gnu.build-id section.
>>
>> Thanks, I'll take a look. I'm looking for something that I can put as
>> a "magic number" at the bottom of some shared memory, and the build-id
>> is ideal since it can be set to a fixed value during debugging.
>
> If I'm reading things properly I have to reimplement
> TElfResourceReader.Load so I can get a subreader, call the FindSection
> method to get a section index, then do something... I've not worked this
> out yet and would appreciate any hints... to convert the section index
> into an address/length in the file and read the data.

I find I can do this comparatively easily using ExeInfo.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal