Bug 22492 - Incorrect note section alignment
Summary: Incorrect note section alignment
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.30
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-25 13:55 UTC by H.J. Lu
Modified: 2022-04-20 15:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2017-11-25 13:55:46 UTC
[hjl@gnu-tools-1 gas]$ cat /tmp/x.s
 .version "Version 1.0"
[hjl@gnu-tools-1 gas]$ gcc -c /tmp/x.s -m32
[hjl@gnu-tools-1 gas]$ readelf -SW x.o
There are 8 section headers, starting at offset 0xd0:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000034 000000 00  AX  0   0  1
  [ 2] .data             PROGBITS        00000000 000034 000000 00  WA  0   0  1
  [ 3] .bss              NOBITS          00000000 000034 000000 00  WA  0   0  1
  [ 4] .note             NOTE            00000000 000034 000018 00      0   0  1
  [ 5] .symtab           SYMTAB          00000000 00004c 000050 10      6   5  4
  [ 6] .strtab           STRTAB          00000000 00009c 000001 00      0   0  1
  [ 7] .shstrtab         STRTAB          00000000 00009d 000032 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)
[hjl@gnu-tools-1 gas]$ 

obj_elf_version pads note section to 4 byte alignment:

frag_align (2, 0, 0);

But it doesn't set section alignment to 4 bytes.
Comment 1 Sourceware Commits 2017-11-27 11:05:53 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit e3d40582166056dd1dfeef2a06ba8f5897b673ee
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Nov 27 11:04:17 2017 +0000

    When creating a .note section to contain a version note, set the section alignment to 4 bytes.
    
    	PR 22492
    	* config/obj-elf.c (obj_elf_version): Set the alignment of the
    	.note section.
Comment 2 Nick Clifton 2017-11-27 11:08:11 UTC
Hi H.J.

  OK - I have checked in the obvious fix.  But .. do we need 8 byte
  alignment on 64-bit targets ?

Cheers
  Nick
Comment 3 H.J. Lu 2017-11-27 12:42:36 UTC
(In reply to Nick Clifton from comment #2)
> Hi H.J.
> 
>   OK - I have checked in the obvious fix.  But .. do we need 8 byte
>   alignment on 64-bit targets ?
> 

Given that .note.ABI-tag and .note.gnu.build-id are aligned to 4
bytes in 64-bit objects, we can keep it aligned to 4 bytes in 64-bit
objects.
Comment 4 Nick Clifton 2017-11-27 14:20:49 UTC
An extra patch is not needed.
Comment 5 Alan Modra 2017-11-28 22:48:31 UTC
Was the patch in comment #1 posted to the mailing list?  There's a small nit..  I think it should be using record_alignment rather than bfd_set_section_alignment.
Comment 6 Sourceware Commits 2017-11-29 09:34:11 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit ed9c7ee03780b8d5acf091091ded29cd40df8254
Author: Nick Clifton <nickc@redhat.com>
Date:   Wed Nov 29 09:32:49 2017 +0000

    Use the record_alignment function when creating a .note section, in case the user has already created the section.
    
    	PR 22492
    	* config/obj-elf.c (obj_elf_version): Use record_alignment rather
    	than bfd_set_section_alignment.
Comment 7 Nick Clifton 2017-11-29 09:35:31 UTC
Hi Alan,

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

> Was the patch in comment #1 posted to the mailing list?

Sorry no - that was my bad.

> There's a small nit.. 
> I think it should be using record_alignment rather than
> bfd_set_section_alignment.

So it should.  I have checked in this patch to fix the problem.

Cheers
  Nick

gas/ChangeLog
2017-11-29  Nick Clifton  <nickc@redhat.com>

	PR 22492
	* config/obj-elf.c (obj_elf_version): Use record_alignment rather
	than bfd_set_section_alignment.


diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 2d1d1679b8..61c573a5e4 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -1829,7 +1829,7 @@ obj_elf_version (int ignore ATTRIBUTE_UNUSED)
       bfd_set_section_flags (stdoutput,
 			     note_secp,
 			     SEC_HAS_CONTENTS | SEC_READONLY);
-      bfd_set_section_alignment (stdoutput, note_secp, 2);
+      record_alignment (note_secp, 2);
 
       /* Process the version string.  */
       len = strlen (name) + 1;
Comment 8 crunte 2021-09-27 15:13:13 UTC Comment hidden (spam)
Comment 9 wnmacy 2022-02-28 16:00:52 UTC Comment hidden (spam)
Comment 10 o.rsanntac 2022-03-11 15:30:58 UTC Comment hidden (spam)
Comment 11 Holly.Troup-Muniz 2022-03-23 15:49:17 UTC Comment hidden (spam)
Comment 12 corkery.flavie 2022-04-20 15:12:53 UTC Comment hidden (spam)