Make the assembler generate an error if there is an attempt to define a section with...
authorNick Clifton <nickc@redhat.com>
Wed, 8 Jan 2020 16:30:20 +0000 (16:30 +0000)
committerNick Clifton <nickc@redhat.com>
Wed, 8 Jan 2020 16:30:20 +0000 (16:30 +0000)
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.

gas/ChangeLog
gas/config/obj-elf.c
gas/testsuite/gas/elf/elf.exp
gas/testsuite/gas/elf/pr14891.d [new file with mode: 0644]
gas/testsuite/gas/elf/pr14891.l [new file with mode: 0644]
gas/testsuite/gas/elf/pr14891.s [new file with mode: 0644]

index 46ce02ee6509892a5d201194241dc5318f74d525..799c591811285a81d25b2796146d46e605e9f125 100644 (file)
@@ -1,3 +1,13 @@
+2020-01-08  Nick Clifton  <nickc@redhat.com>
+
+       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.
+
 2020-01-08  Alan Modra  <amodra@gmail.com>
 
        * config/tc-z8k.c (md_begin): Make idx unsigned.
index ffc5508532f43a03e46509324a09fc45811b0eba..7cf921c051f62b4cd73b867e7d203cc3fec284fe 100644 (file)
@@ -1039,6 +1039,18 @@ obj_elf_section (int push)
   name = obj_elf_section_name ();
   if (name == NULL)
     return;
+
+  symbolS * sym;
+  if ((sym = symbol_find (name)) != NULL
+      && ! symbol_section_p (sym)
+      && S_IS_DEFINED (sym)
+      && ! S_IS_VOLATILE (sym)
+      && ! S_CAN_BE_REDEFINED (sym))
+    {
+      as_bad (_("section name '%s' already defined as another symbol"), name);
+      ignore_rest_of_line ();
+      return;
+    }
   type = SHT_NULL;
   attr = 0;
   gnu_attr = 0;
index 560071caffb5f59a6e84bcb2e83eedfdfb3ed84b..746ff7eea0ddb323a18ed64a5699e6734be890dc 100644 (file)
@@ -209,6 +209,7 @@ if { [is_elf_format] } then {
     }
     run_dump_test "symver"
     run_dump_test "pr21661"
+    run_dump_test "pr14891"
 
     # No indirect functions on non-GNU targets.
     # The Visium and MSP set the ELF header's OSABI field to ELFOSABI_STANDALONE.
diff --git a/gas/testsuite/gas/elf/pr14891.d b/gas/testsuite/gas/elf/pr14891.d
new file mode 100644 (file)
index 0000000..c15f28c
--- /dev/null
@@ -0,0 +1,2 @@
+#name: defining a section with the same name as a symbol
+#error_output: pr14891.l
diff --git a/gas/testsuite/gas/elf/pr14891.l b/gas/testsuite/gas/elf/pr14891.l
new file mode 100644 (file)
index 0000000..4013ec1
--- /dev/null
@@ -0,0 +1,3 @@
+[^:]*: Assembler messages:
+[^:]*:3: Error: section name 'foo' already defined as another symbol
+[^:]*:6: Error: symbol `bar' is already defined
diff --git a/gas/testsuite/gas/elf/pr14891.s b/gas/testsuite/gas/elf/pr14891.s
new file mode 100644 (file)
index 0000000..f8e1832
--- /dev/null
@@ -0,0 +1,6 @@
+
+foo:
+.section foo, "a"
+
+.section bar, "a"
+bar: