Bug 621742

Summary: linker script doesn't allow section name patterns with caret symbol (^)
Product: [Fedora] Fedora Reporter: Denys Vlasenko <dvlasenk>
Component: binutilsAssignee: Nick Clifton <nickc>
Status: CLOSED EOL QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 19CC: dvlasenk, jakub, nickc
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-02-18 06:05:31 EST Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:

Description Denys Vlasenko 2010-08-05 21:59:43 EDT
In ld linker script I need to collect all sections with names like .text.foo, where foo itself does not start with the dot.

Ideally, the following rule would do it:


.text: { *(.text.[^.]* )

but ld does not allow [^...] glob pattern element. So I was using

.text: { *(.text.[A-Za-z0-9_$]* )

hoping that this set of chars is covering all section names generated by gcc, as and ld.

But James Bottomley says that on parisc, ld sometimes generates names with caret (^) in them. So I added caret too:

.text: { *(.text.[A-Za-z0-9_$^]* )

This does not work. I'm getting "ignoring invalid character '^' in script" error message from linker. Apparently, caret is not allowed in section name patterns.

The message comes from binutils-2.20.1/ld/ldlex.l:460

<SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>.  lex_warn_invalid (" in script", yytext);

I think this can be fixed by adding caret to WILDCHAR definition in the same file, and regenerating ldlex.c from it. Currently the definition is

WILDCHAR        [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*]

and I propose to change it to

WILDCHAR        [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*\^]
Comment 1 Denys Vlasenko 2010-08-05 22:09:30 EDT
Oops.. I made a mistake in the first directive example, and then cut-n-pasted it, so all examples have the same mistake...

instead of

.text: { *(.text.[^.]* )

it should be

.text: { *(.text.[^.]*) }
Comment 2 Andreas Schwab 2010-08-09 08:46:40 EDT
The right way to negate a character class is to use ! as the first character (see glob(7)).
Comment 3 Denys Vlasenko 2010-08-12 10:12:44 EDT
Thanks Andreas, I did not know that.

Unfortunately, the [!foo] construct seems to be rejected:

I performed the following test:

Created a test module test.c:

void __attribute__((section(".text..f"))) f() {}
void __attribute__((section(".text.g"))) g() {}

Produced test.o:

$ gcc -c test.c

"Incrementally linked" it into a test1.o, adding --verbose to recover the internal linker script:

$ ld -r -o test1.o test.o --verbose >test.lds

Edited test.lds: removed everything except linker script, and added

.text.nodot : { *(.text.[!.]*) }

just before existing ".text: ...." rule.

When I try to use the script, ld errors out:

$ ld -r -o test1.o test.o -T test.lds
ld:test.lds:44: syntax error

Same happens with

.text.nodot : { *(.text.[!A-Z]*) }

rule, so it's not because of the dot inside [].

.text.nodot : { *(.text.[.]*) }

works, thus I conclude that it's [!foo] construct that is not supported.

$ ld --version
GNU ld version 2.20.51.0.2-20.fc13 20091009
Comment 4 Nick Clifton 2010-08-20 11:15:34 EDT
Hi Denys,

  Thanks for reporting this bug.  You were right the caret character ought to be able to invert the sense of the match.  Andreas was also correct in that the exclamation point character should have been able to do the same thing.  In fact *both* characters ought to be added to the WILDCHAR definition and this is exactly what I have done with the latest rawhide binutils rpm (binutils-2.20.51.0.10-3.fc15).

  Incidentally there is another way to solve the original problem if you do not mind the sections containing two successive period characters appearing before the sections containing only single period characters.  Like this:

  .text : { *(*.text) *(.text..*) }
  .text.nodot : { *(.text.*) }

Cheers
  Nick Clifton
Comment 5 Denys Vlasenko 2010-08-31 11:52:57 EDT
Thanks!
Comment 6 Denys Vlasenko 2010-09-10 11:36:05 EDT
> In
> fact *both* characters ought to be added to the WILDCHAR definition and this is
> exactly what I have done with the latest rawhide binutils rpm
> (binutils-2.20.51.0.10-3.fc15).

Will it go into next upstream release too?
Comment 7 Nick Clifton 2010-09-10 12:03:09 EDT
Yes.
Comment 8 Fedora End Of Life 2013-04-03 16:34:50 EDT
This bug appears to have been reported against 'rawhide' during the Fedora 19 development cycle.
Changing version to '19'.

(As we did not run this process for some time, it could affect also pre-Fedora 19 development
cycle bugs. We are very sorry. It will help us with cleanup during Fedora 19 End Of Life. Thank you.)

More information and reason for this action is here:
https://fedoraproject.org/wiki/BugZappers/HouseKeeping/Fedora19
Comment 9 Fedora End Of Life 2015-01-09 17:28:14 EST
This message is a notice that Fedora 19 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 19. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained. Approximately 4 (four) weeks from now this bug will
be closed as EOL if it remains open with a Fedora 'version' of '19'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 19 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.
Comment 10 Fedora End Of Life 2015-02-18 06:05:31 EST
Fedora 19 changed to end-of-life (EOL) status on 2015-01-06. Fedora 19 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.