[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-01 Thread tkacvins at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

Tom Kacvinsky  changed:

   What|Removed |Added

 CC||tkacvins at gmail dot com

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-01 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

Nick Clifton  changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2023-03-01
 Status|UNCONFIRMED |ASSIGNED
 CC||nickc at redhat dot com

--- Comment #1 from Nick Clifton  ---
(In reply to Tom Kacvinsky from comment #0)
Hi Tom,

> Results in the ld.gold version not being in the .comment section. 

But - just to be clear - it is in the .note.gnu.gold-version section:

  % readelf -p.note.gnu.gold-version a.out

  String dump of section '.note.gnu.gold-version':
[ c]  GNU
[10]  gold 1.16

So this is a request for gold to add or move the version number into the
.comment
section, right ?  And add the feature to ld too, of course.


Note - it is possible to achieve the desired effect using an extra object file:

  % cat ld-version.s
.section .comment   
.asciz "GNU ld version 2.37-37.fc36";
  % gcc hello.c ld-version.s
  % readelf -p.comment
   [ 0]  GCC: (GNU) 12.2.1 20221121 (Red Hat 12.2.1-4)
   [2e]  GCC: (GNU) 12.0.1 20220413 (Red Hat 12.0.1-0)
   [5c]  GNU ld version 2.37-37.fc36

But I am sure that this is not what you want.

Hmm, let me see if it is an easy thing to do...

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-01 Thread tkacvins at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #2 from Tom Kacvinsky  ---
(In reply to Nick Clifton from comment #1)
> (In reply to Tom Kacvinsky from comment #0)
> Hi Tom,
>  
> > Results in the ld.gold version not being in the .comment section. 
> 
> But - just to be clear - it is in the .note.gnu.gold-version section:
> 
>   % readelf -p.note.gnu.gold-version a.out
> 
>   String dump of section '.note.gnu.gold-version':
> [ c]  GNU
> [10]  gold 1.16
> 
> So this is a request for gold to add or move the version number into the
> .comment section, right ?  And add the feature to ld too, of course.

Yes, this is correct - to make it more in line with what LLD does.
> 
> 
> Note - it is possible to achieve the desired effect using an extra object
> file:
> 
>   % cat ld-version.s
>   .section .comment   
>   .asciz "GNU ld version 2.37-37.fc36";
>   % gcc hello.c ld-version.s
>   % readelf -p.comment
>[ 0]  GCC: (GNU) 12.2.1 20221121 (Red Hat 12.2.1-4)
>[2e]  GCC: (GNU) 12.0.1 20220413 (Red Hat 12.0.1-0)
>[5c]  GNU ld version 2.37-37.fc36
> 
> But I am sure that this is not what you want.
> 

This is feasible in that we can use cmake to generate the .s file, or
perhaps generated a new object file everything we upgrade binutils.

But...

> Hmm, let me see if it is an easy thing to do...

This would be ideal if you or someone on the binutils team can do it.

Thanks!

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-03 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #3 from Nick Clifton  ---
Created attachment 14728
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14728&action=edit
Proposed patch

Hi Tom,

  What do you think of the this patch ?

  It adds a new linker script directive called LINKER_VERSION, which if used
  inserts the current linker version identity string at the current location.
  Then it enhances the default linker script for (most) ELF based targets so
  that this directive is added to the end of the .comment section.

  Using a linker script directive means that the string can be placed whever
  the user wishes (by creating their own linker scripts) or not at all (again
  with a custom script).

  Here is an example of it in use:

  % gcc -c hello.c
  % ld hello.o -e 0 --defsym printf=0 
  % readelf -p.comment a.out
  String dump of section '.comment':
[ 0]  GCC: (GNU) 12.0.1 20220413 (Red Hat 12.0.1-0)
[2e]  GNU ld (GNU Binutils) 2.40.50.20230303

  % ld --verbose | grep comment
  .comment   0 : { *(.comment); LINKER_VERSION; }

Cheers
  Nick

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-03 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #4 from Nick Clifton  ---
(In reply to Nick Clifton from comment #3)

>   What do you think of the this patch ?

I have discovered a flaw in the patch. :-(  

Since the version string is now present in the .comment section, that section
is always output, even if there are no input files containing .comment
sections.  This breaks many of the linker's own tests and represents unexpected
new behaviour of the linker.  *sigh*  I will have to rethink my solution.

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-03 Thread tkacvins at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #5 from Tom Kacvinsky  ---
(In reply to Nick Clifton from comment #4)
> (In reply to Nick Clifton from comment #3)
>  
> >   What do you think of the this patch ?
>  
> I have discovered a flaw in the patch. :-(  
> 
> Since the version string is now present in the .comment section, that
> section is always output, even if there are no input files containing
> .comment sections.  This breaks many of the linker's own tests and
> represents unexpected new behaviour of the linker.  *sigh*  I will have to
> rethink my solution.

I'd be OK with a new option.  That way, old tests can be such that the new
option is not used, the .comment section is not emitted, and things are as they
were. Then, write a new test (or tests) that exercise the new option.  I see
there is often a lot of back and forth on the binutils list about what options
should be named, but just as a first stabd, I'd call it
"--emit-comment-section"

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-03 Thread tkacvins at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #6 from Tom Kacvinsky  ---
I found an issue with the patch.  I applied against master and built it.  I
then used gcc 12.1.0 and got this:

$ /opt/gcc-12.1.0/bin/gcc -B /opt/binutils-2.40-version/bin -fuse-ld=bfd -o
wchar wchar.c

/opt/binutils-2.40-version/bin/ld.bfd: wchar: error: PHDR segment not covered
by LOAD segment

If I dump the default linker script and remove the linker version comment
option, and use the resulting file as the link scriot:

$ /opt/gcc-12.1.0/bin/gcc -B /opt/binutils-2.40-version/bin -fuse-ld=bfd
-Wl,--script=noversion.script -o wchar wchar.c

this problem goes away.

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-14 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

Nick Clifton  changed:

   What|Removed |Added

  Attachment #14728|0   |1
is obsolete||

--- Comment #7 from Nick Clifton  ---
Created attachment 14751
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14751&action=edit
Proposed patch

Hi Tom,

  (Sorry for the delay in updating this PR).

  Please could you try out this revised patch ?

  It uses the same LINKER_VERSION linker script directive, but this time it is
also
  controlled via a new command line option: --enable-linker-version.

  I would be interested to know if the problem you observed compiling wchar.c
returns, if you link with -Wl,--enable-linker-version.  If it does, please
could you upload the wchar.c or whcar.o files so that I can try for myself.

Cheers
  Nick

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-14 Thread tkacvins at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #8 from Tom Kacvinsky  ---
Created attachment 14752
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14752&action=edit
simple C reproducer file

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-14 Thread tkacvins at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #9 from Tom Kacvinsky  ---
(In reply to Nick Clifton from comment #7)
> Created attachment 14751 [details]
> Proposed patch
> 
> Hi Tom,
> 
>   (Sorry for the delay in updating this PR).
> 
>   Please could you try out this revised patch ?
> 
>   It uses the same LINKER_VERSION linker script directive, but this time it
> is also
>   controlled via a new command line option: --enable-linker-version.
> 
>   I would be interested to know if the problem you observed compiling
> wchar.c returns, if you link with -Wl,--enable-linker-version.  If it does,
> please could you upload the wchar.c or whcar.o files so that I can try for
> myself.
> 
> Cheers
>   Nick

I have attached the wchar.c file I am using.  But this problem happens with an
even more simple C file

int main()
{
  return 0;
}

The error with PHDR happens with use of -Wl,--enable-linker-version and
-fuse-ld=bfd, but not when --enable-linker-version is not used.

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-15 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

Nick Clifton  changed:

   What|Removed |Added

  Attachment #14751|0   |1
is obsolete||

--- Comment #10 from Nick Clifton  ---
Created attachment 14754
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14754&action=edit
Proposed patch

Hi Tom,

  Found it - forcing the .comment section to load at address 0 causes the
problems.

  Please try out this revised patch and let me know if you still have issues.

Cheers
  Nick

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-15 Thread tkacvins at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #11 from Tom Kacvinsky  ---
Hi Nick,

This worked perfectly.  The linker didn't throw the PHDR error, and the
resulting executable now has the binutils version in the .comment section.

Thank you very much for your work on this.  So you know, the impetus for this
is I build a lot of different things for my job and don't always remember to
use the linker I should for code I am building.  This will help me decipher if
I used the right linker or not.

Tom

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-15 Thread cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #12 from cvs-commit at gcc dot gnu.org  ---
The master branch has been updated by Nick Clifton :

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2d5783fad77c2cb9cdcb396d65fe0a60e3d8938b

commit 2d5783fad77c2cb9cdcb396d65fe0a60e3d8938b
Author: Nick Clifton 
Date:   Wed Mar 15 14:27:21 2023 +

Add --enable-linker-version option to bfd linker to add an entry in the
.comment section.

   PR 30187
  * NEWS: Mention the new feature. * ld.texi: Document the new feature. *
ldgram.y: Handle LINKER_VERSION token. * ldlang.c (lang_add_version): New
function. (enable_linker_version): New global variable. * ldlang.h
(land_add_version): Prototype. (enable_linker_version): Export. * ldlex.h
(OPTION_ENABLE_LINKER_VERSION): Define. (OPTION_DISABLE_LINKER_VERSION):
Define. * ldlex.l (LINKER_VERSION): Add token. * lexsup.c (ld_options): Add
--enable-linker-version and --disable-linker-version. (parse_args): Handle the
new options. * scripttempl/arclinux.sc: Remove stabs and comment sections and
replace with inclusion of misc-sections.sc * scripttempl/avr.sc: Likewise. *
scripttempl/dlx.sc: Likewise. * scripttempl/elf.sc: Likewise. *
scripttempl/elf32cr16.sc: Likewise. * scripttempl/elf32crx.sc: Likewise. *
scripttempl/elf32msp430.sc: Likewise. * scripttempl/elf64bpf.sc: Likewise. *
scripttempl/elf64hppa.sc: Likewise. * scripttempl/elf_chaos.sc: Likewise. *
scripttempl/elfarc.sc: Likewise. * scripttempl/elfarcv2.sc: Likewise. *
scripttempl/elfd10v.sc: Likewise. * scripttempl/elfd30v.sc: Likewise. *
scripttempl/elfm68hc11.sc: Likewise. * scripttempl/elfm68hc12.sc: Likewise. *
scripttempl/elfm9s12z.sc: Likewise. * scripttempl/elfmicroblaze.sc: Likewise. *
scripttempl/elfxgate.sc: Likewise. * scripttempl/elfxtensa.sc: Likewise. *
scripttempl/epiphany_4x4.sc: Likewise. * scripttempl/ft32.sc: Likewise. *
scripttempl/ip2k.sc: Likewise. * scripttempl/iq2000.sc: Likewise. *
scripttempl/mep.sc: Likewise. * scripttempl/nds32elf.sc: Likewise. *
scripttempl/pru.sc: Likewise. * scripttempl/v850.sc: Likewise. *
scripttempl/v850_rh850.sc: Likewise. * scripttempl/visium.sc: Likewise. *
scripttempl/xstormy16.sc: Likewise. * scripttempl/z80.sc: Likewise. *
testsuite/ld-scripts/script.exp: Run new tests. * scripttempl/misc-sections.sc:
New file. * testsuite/ld-scripts/ld-version-2.d: New file. *
testsuite/ld-scripts/ld-version.d: New file. *
testsuite/ld-scripts/ld-version.t: New file.

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-15 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #13 from Nick Clifton  ---
Hi Tom,

  Right - that is the bfd linker sorted.

  I am hoping that someone else will volunteer to look at the gold
  linker however, as I am not very good at C++...

Cheers
  Nick

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-16 Thread cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #14 from cvs-commit at gcc dot gnu.org  ---
The master branch has been updated by Alan Modra :

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6752dd75f76457902729a5f03d09fa28ec5d68c3

commit 6752dd75f76457902729a5f03d09fa28ec5d68c3
Author: Alan Modra 
Date:   Thu Mar 16 17:10:07 2023 +1030

Re: Add --enable-linker-verssion

Output sections without any input sections to initialise their flags
have their flags initialised by data statements to LOAD, ALLOC,
HAS_CONTENTS by default.  This is wrong for .comment.  Fix that by
making the script initialise the section type to INFO, one of the
noalloc section types.  That also allows the address of .comment to be
set to zero, as is usual for non-alloc sections.

Also, use source_sh for all of the sourced scripts to set up make
dependencies.

PR 30187
* scripttempl/misc-sections.sc: Set .comment address to zero
and type to INFO.
* scripttempl/ft32.sc: Fix breakages from last edit.
* scripttempl/arclinux.sc: Use source_sh to source DWARF.sc
and misc-sections.sc.
* scripttempl/avr.sc: Likewise.
* scripttempl/dlx.sc: Likewise.
* scripttempl/elf.sc: Likewise.
* scripttempl/elf32cr16.sc: Likewise.
* scripttempl/elf32crx.sc: Likewise.
* scripttempl/elf32msp430.sc: Likewise.
* scripttempl/elf64bpf.sc: Likewise.
* scripttempl/elf64hppa.sc: Likewise.
* scripttempl/elf_chaos.sc: Likewise.
* scripttempl/elfarc.sc: Likewise.
* scripttempl/elfarcv2.sc: Likewise.
* scripttempl/elfd10v.sc: Likewise.
* scripttempl/elfd30v.sc: Likewise.
* scripttempl/elfm68hc11.sc: Likewise.
* scripttempl/elfm68hc12.sc: Likewise.
* scripttempl/elfm9s12z.sc: Likewise.
* scripttempl/elfmicroblaze.sc: Likewise.
* scripttempl/elfxgate.sc: Likewise.
* scripttempl/elfxtensa.sc: Likewise.
* scripttempl/epiphany_4x4.sc: Likewise.
* scripttempl/i386beos.sc: Likewise.
* scripttempl/i386go32.sc: Likewise.
* scripttempl/ia64vms.sc: Likewise.
* scripttempl/ip2k.sc: Likewise.
* scripttempl/iq2000.sc: Likewise.
* scripttempl/mep.sc: Likewise.
* scripttempl/mmo.sc: Likewise.
* scripttempl/nds32elf.sc: Likewise.
* scripttempl/pru.sc: Likewise.
* scripttempl/v850.sc: Likewise.
* scripttempl/v850_rh850.sc: Likewise.
* scripttempl/visium.sc: Likewise.
* scripttempl/xstormy16.sc: Likewise.
* scripttempl/z80.sc: Likewise.
* testsuite/ld-scripts/ld-version-2.d: Don't skip ft32 or pru.

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-24 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #15 from Nick Clifton  ---
Created attachment 14778
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14778&action=edit
Proposed patch

Hi Tom,

  Well I have dusted off my C++ programming skills and had a go at adding the
  feature to gold.  So please can you try out the uploaded patch and let me
  know what you think.

  It adds a new command line option to gold: --enable-linker-version.  If used
  then the gold version string is added to the .comment section (which is
created
  if necessary).  If not used then the version string is placed into the
  .note.gnu.gold-version section as normal.

Cheers
  Nick

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-24 Thread tkacvins at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #16 from Tom Kacvinsky  ---
Nick,

Worked great!  Thanks!

Tom

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-27 Thread cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

--- Comment #17 from cvs-commit at gcc dot gnu.org  ---
The master branch has been updated by Nick Clifton :

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=eb42b9d6f914b233d740da88d5e21c6690170b7d

commit eb42b9d6f914b233d740da88d5e21c6690170b7d
Author: Nick Clifton 
Date:   Mon Mar 27 11:10:10 2023 +0100

Add an option to the gold linker to put its version string into the
.comment section.

  PR 30187
  * options.h (class General_options): Add enable-linker-version.
  * layout.cc (Layout::create_gold_note): If linker-version is enabled put
the version string into the .comment section.

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


[Bug gold/30187] ld.bfd and ld.gold versions in .comment section of ELF files

2023-03-27 Thread nickc at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30187

Nick Clifton  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #18 from Nick Clifton  ---
Right - gold patch applied.

That takes care of both linkers, so I am closing this PR.

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