Bug 25570 - [ld] Duplicate "warning: changing start of section"
Summary: [ld] Duplicate "warning: changing start of section"
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-17 22:53 UTC by Fangrui Song
Modified: 2020-03-05 11:22 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed: 2020-03-04 00:00:00


Attachments
not so awful fix (1.33 KB, patch)
2020-03-04 11:31 UTC, Alan Modra
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-02-17 22:53:35 UTC
cat > a.x <<e
 SECTIONS {
  .text 0x1000 : {}
  .data.rel.ro . : ALIGN(16) {}
  .data 0x2000 : {}
  .bss . : ALIGN(16) {}
 }
e
cat > a.s <<e
 .globl _start; _start: ret
 .section .data.rel.ro; .balign 16; .byte 0
 .section .data; .balign 32; .byte 0
 .section .bss; .byte 0
e

as a.s -o a.o
ld.bfd -T a.x a.o

ld.bfd: warning: changing start of section .data.rel.ro by 15 bytes
ld.bfd: warning: changing start of section .bss by 15 bytes
ld.bfd: warning: changing start of section .data.rel.ro by 15 bytes
ld.bfd: warning: changing start of section .bss by 15 bytes

ld/ldlang.c:lang_size_sections_1 runs multiple times. lang_size_sections_1 should record the changed sections. When the addresses are finalized, print the warnings.
Comment 1 cvs-commit@gcc.gnu.org 2020-03-04 05:58:31 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 91114f7583fac8fdf57c58a1f632839da62e43da
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Mar 4 15:33:26 2020 +1030

    PR25570, ld duplicate "warning: changing start of section"
    
    	PR 25570
    	* ldlang.c (lang_size_sections_1): Delay emitting non-fatal
    	errors/warnings until final pass.
    	* ldexp.c (fold_name): Likewise.
Comment 2 Alan Modra 2020-03-04 05:59:28 UTC
Fixed
Comment 3 Alan Modra 2020-03-04 06:09:54 UTC
Oops, not fixed.
Comment 4 Alan Modra 2020-03-04 08:23:35 UTC
I'm going to close this as wont fix, because the effort required to fix it looks to be large compared to the annoyance of duplicate warnings when either using --warn-section-align or user linker scripts.  Or you'd need to run an extra sizing pass just to report errors, and I don't want to slow down the linker just for this bug.
Comment 5 Alan Modra 2020-03-04 11:31:38 UTC
Created attachment 12344 [details]
not so awful fix

Maybe it's not so hard to fix.  I'll test this one overnight
Comment 6 cvs-commit@gcc.gnu.org 2020-03-04 23:27:49 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit baf09cba8f97be8044f7422cb31b1cb3f23e2762
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Mar 4 21:14:19 2020 +1030

    PR25570, ld duplicate "warning: changing start of section"
    
    Note that because we should report a signed delta from the previous
    VMA it isn't possible to use ngettext.  ngettext only supports
    unsigned long values.  So byte/bytes goes from the message.
    
    	PR 25570
    	* ldlang.c (lang_sizing_iteration): New static var.
    	(lang_size_sections_1): Warn about no memory region only on first
    	iteration.  Warn about changing start address on first iteration
    	then any delta from that on subsequent iterations.  Report a signed
    	delta.
    	(one_lang_size_sections_pass): Increment lang_sizing_iteration.
Comment 7 Alan Modra 2020-03-04 23:31:27 UTC
Patch applied
Comment 8 cvs-commit@gcc.gnu.org 2020-03-05 11:22:57 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 92d4b13bf378f575cdc796ec9340c12267b7eff1
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Mar 5 21:34:23 2020 +1030

    Reduce --warn-section-align output
    
    	PR 25570
    	* ldlang.c (lang_size_sections_1): Don't report changes on
    	second and subsequent iterations that make no change in
    	alignment from that already reported.