bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/27565] ld: Support input section description keyword: REVERSE


From: nickc at redhat dot com
Subject: [Bug ld/27565] ld: Support input section description keyword: REVERSE
Date: Fri, 20 Oct 2023 11:38:12 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=27565

--- Comment #10 from Nick Clifton <nickc at redhat dot com> ---
Hi Alexey,

(In reply to Alexey from comment #9)
> That is what I found.

Thanks for reviewing the patch.

> Issue 1:
> 
> Can not pass multiple sections to REVERSE, e.g:
> *(REVERSE(.init_array .ctors))

This is in line with the other sorting directives.  For example this is illegal
too:

  *(SORT_BY_NAME (.text .data))

This behaviour is even documented in the linker manual:

  SORT_BY_NAME
  Normally, the linker will place files and sections matched 
  by wildcards in the order in which they are seen during the 
  link.  You can change this by using the SORT_BY_NAME
  keyword, which appears before *a* wildcard pattern in 
  parentheses (e.g., SORT_BY_NAME(.text*)}.

(I added the emphasis).

> Can only with combining:
> *(REVERSE(.init_array))
> *(REVERSE(.ctors))

Right - this is the way that script writers are expected to solve this problem.

However I accept that this might be confusing to users, so I am going to extend
the documentation of the sorting commands to include an extra paragraph:

  Note - the sorting commands only accept a single wildcard pattern.
  So for example the following will not work:
       *(REVERSE(.text* .init*))
  To resolve this problem list the patterns individually, like this:
       *(REVERSE(.text*))
       *(REVERSE(.init*))


> Issue 2:
> 
> Reverse does not apply for:
> 
> *(REVERSE(EXCLUDE_FILE (*crtend.* *crtbegin.*) .ctors))

Yes - there was another bug in the changes to the ldgram.y file.  The REVERSE
command is meant to imply SORT_BY_NAME if no sorting command is used, but this
was only happening for file names and not for section names.

Note - you may have also noticed that the following is not accepted:

  *(EXCLUDE_FILE (*crtend.* *crtbegin.*) REVERSE(.ctors))

Supporting this form would mean even more changes to the grammar, which I would
rather avoid unless really necessary.  Instead I would prefer to add another
paragraph to the documentation:

  Note - you can put the 'EXCLUDE_FILE' command inside a sorting
  command, but not the other way around.  So for example:
       *(SORT_BY_NAME(EXCLUDE_FILE(foo) .text*))
   will work, but:
       *(EXCLUDE_FILE(foo) SORT_BY_NAME(.text*))
   will not.


> ? Issue 3:
> 
> The first element is 0xffffffff for:
> *(REVERSE(.ctors))
> 
> I would like to not change the place of terminating 0xffffffff ctors.

No, I think that this is not something that should be supported.  Changing the
order of the constructors is a very bad idea, and legitimizing it by adding
code to handle the terminating -1 is not something that I think we should do.

Please try out the revised patch and let me know if you are happy with it.

Cheers
  Nick

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]