Bug 14891 - Section name and symbol name clash
Summary: Section name and symbol name clash
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-29 05:45 UTC by Dmitry Gorbachev
Modified: 2020-01-08 16:33 UTC (History)
2 users (show)

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


Attachments
Testcases (ELF) (131 bytes, text/plain)
2012-11-29 05:45 UTC, Dmitry Gorbachev
Details
Testcases (PE-COFF) (91 bytes, text/plain)
2012-11-29 05:49 UTC, Dmitry Gorbachev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2012-11-29 05:45:05 UTC
Created attachment 6762 [details]
Testcases (ELF)

The 1st testcase fails with an error:

$ as 1.s -o 1.o --defsym X=1
1.s: Assembler messages:
1.s:18: Warning: section symbols are already global
1.s:23: Error: symbol `foo' is already defined

But in the 2nd case, a symbol silently disappears:

$ as 1.s -o 1.o
$ nm -a 1.o
00000000 D bar
00000000 b .bss
00000000 d .data
00000000 d foo
00000000 t .text
Comment 1 Dmitry Gorbachev 2012-11-29 05:49:39 UTC
Created attachment 6763 [details]
Testcases (PE-COFF)

No error/disappearance for PE-COFF targeted AS:

$ as 2.s -o 2.o
$ nm -a 2.o
00000000 D _bar
00000000 b .bss
00000000 d .data
00000000 ? fake
00000000 d _foo
00000000 B _foo
00000000 t .text
Comment 2 Fangrui Song 2019-12-16 04:28:13 UTC
A simpler reproduce for the ELF test case.

% cat a.s
foo:
.section foo
% as a.s  # no diagnostic

% cat b.s
.section foo
foo:
% as b.s
b.s: Assembler messages:
b.s:2: Error: symbol `foo' is already defined


There should be an error in both cases.
Comment 3 Sourceware Commits 2020-01-08 16:31:44 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit f1f28025c3ea75d5368ddd3046461648145b89b3
Author: Nick Clifton <nickc@redhat.com>
Date:   Wed Jan 8 16:30:20 2020 +0000

    Make the assembler generate an error if there is an attempt to define a section with the same name as an already defined symbol.
    
    	PR 14891
    	* config/obj-elf.c (obj_elf_section): Fail if the section name is
    	already defined as a different symbol type.
    	* testsuite/gas/elf/pr14891.s: New test source file.
    	* testsuite/gas/elf/pr14891.d: New test driver.
    	* testsuite/gas/elf/pr14891.s: New test expected error output.
    	* testsuite/gas/elf/elf.exp: Run the new test.
Comment 4 Nick Clifton 2020-01-08 16:33:44 UTC
I have checked in a patch that fixes the test case using .section.  There may however be other ways of triggering a name conflict that I have not considered.  If so then this PR can be reopened.