public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Ulf Samuelsson <binutils@emagii.com>
To: Fangrui Song <i@maskray.me>
Cc: binutils@sourceware.org, nickc@redhat.com
Subject: Re: [RFC v0 0/1] Add support for CRC64 generation in linker
Date: Thu, 16 Feb 2023 23:37:46 +0100	[thread overview]
Message-ID: <8c80d58c-8c43-90c9-9d0b-9a5de91c16ed@emagii.com> (raw)
In-Reply-To: <DS7PR12MB57657A0E46493FAAA203AF77CBA09@DS7PR12MB5765.namprd12.prod.outlook.com>


Den 2023-02-16 kl. 22:30, skrev Fangrui Song:
> On Thu, Feb 16, 2023 at 12:40 PM Ulf Samuelsson via Binutils
> <binutils@sourceware.org> wrote:
>> Cleaned up attempt to generate CRC64.
>>
>>
>> Added code in lang_end() to calculate the CRC.
>> So far, I can retrieve the location of the CRC
>> and the start and end for the area.
>> I can fetch the .text segment as an asection but
>>
>>    if ( bfd_get_section_contents (link_info.output_bfd,
>>            ts,
>>            text_section,
>>            0,
>>            ts->size))
>>
>> fails...
>>
>> The patchset should contain the LICENSE and the testsuite
>> but git-send-email does not like if I send 8 patches.
>> Sending 6 patches is OK for some reason...
>>
>> [PATCH v0 1/6] CRC64 header
>> [PATCH v0 2/6] ldlang.h: CRC64
>> [PATCH v0 3/6] ldlex.l: CRC64
>> [PATCH v0 4/6] ldgram.y: CRC64
>> [PATCH v0 5/6] ldlang.c: CRC64
>> [PATCH v0 6/6] ldlang.c: Try to get the .text section for checking
>>
> Hi Ulf, can you state why a built-in support of ld is needed? If you
> want to embed a checksum, you can use Output Section Data to reserve a
> few bytes in the output, then use a post-link tool to compute the
> checksum and rewrite the reserved bytes.

Yes, this is what I have been doing so far, and I am not happy about it.

In my experience, the post link tools usually work on the binary data 
and not the ELF file.
The IAR ielftool that I ported is an exception, but it is not 100% 
compatible with the result of the GNU linker.

That means that you cannot load the ELF file into a debugger and run,
because you do not have the CRC in the ELF file, only in the 
binary/hex-file.

Another thing is that the post-link tools I have seen are typically 
poorly maintained.

Adding a post-link step seems like a kludge if the linker can provide 
the CRC inside the ELF file.

> I am asking because I am unsure whether this feature is generic enough
> to meet a majority of future users' needs. We can reasonably expect
> that other users may want to use different message digest
> algorithms...

The feature allows a CRC-64 to be generated using either ECMA, ISO or a 
user defined polynom.
This means that you cannot make a more generic CRC-64.

The only projects I can see that would need anything else are 8 bit 
micros with a few kB of flash.
They could use a CRC-32 and may trade off speed for code size using a 
non-table driven version.

Adding this functionality does not mean that a user have to use it.
They can continue to use a post-link tool to create CRC64 or any other CRC.
If they want something else, they can do that as well.

For those that do want CRC64, this simplifes things a lot.

> Cheers

Best Regards
Ulf Samuelsson



  parent reply	other threads:[~2023-02-16 22:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16 20:40 binutils
2023-02-16 20:40 ` [PATCH v0 1/6] CRC64 header binutils
2023-02-16 20:40 ` [PATCH v0 2/6] ldlang.h: CRC64 binutils
2023-02-16 20:40 ` [PATCH v0 3/6] ldlex.l: CRC64 binutils
2023-02-16 20:40 ` [PATCH v0 4/6] ldgram.y: CRC64 binutils
2023-02-16 20:40 ` [PATCH v0 5/6] ldlang.c: CRC64 binutils
2023-02-16 20:40 ` [PATCH v0 6/6] ldlang.c: Try to get the .text section for checking CRC binutils
2023-02-16 21:30 ` [RFC v0 0/1] Add support for CRC64 generation in linker Fangrui Song
     [not found] ` <DS7PR12MB57657A0E46493FAAA203AF77CBA09@DS7PR12MB5765.namprd12.prod.outlook.com>
2023-02-16 22:37   ` Ulf Samuelsson [this message]
2023-02-17 11:11     ` Nick Clifton
2023-02-17 12:03       ` Ulf Samuelsson
2023-03-06  7:50         ` Fangrui Song
     [not found]         ` <DS7PR12MB57654E11983392D5DCBF1D85CBB69@DS7PR12MB5765.namprd12.prod.outlook.com>
2023-03-06 10:00           ` Ulf Samuelsson
2023-02-17  7:53 ` Ulf Samuelsson
2023-02-17 10:55   ` Nick Clifton
     [not found] ` <DS7PR12MB5765096101240054A648F8C9CBA09@DS7PR12MB5765.namprd12.prod.outlook.com>
2023-02-17 10:46   ` Nick Clifton
  -- strict thread matches above, loose matches on Subject: below --
2023-02-16 13:19 binutils
2023-02-16 13:21 ` Ulf Samuelsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c80d58c-8c43-90c9-9d0b-9a5de91c16ed@emagii.com \
    --to=binutils@emagii.com \
    --cc=binutils@sourceware.org \
    --cc=i@maskray.me \
    --cc=nickc@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).