]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
pdp11: Fix handling of common (local and global) vars [PR94134]
authorJakub Jelinek <jakub@redhat.com>
Wed, 11 Mar 2020 17:35:13 +0000 (18:35 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 17 Mar 2020 17:13:12 +0000 (18:13 +0100)
As mentioned in the PR, the generic code decides to put the a variable into
lcomm_section, which is a NOSWITCH section and thus the generic code doesn't
switch into a particular section before using
ASM_OUTPUT{_ALIGNED{,_DECL}_}_LOCAL, on many targets that results just in
.lcomm (or for non-local .comm) directives which don't need a switch to some
section, other targets put switch_to_section (bss_section) at the start of
that macro.
pdp11 doesn't do that (and doesn't have bss_section), and so emits the
lcomm/comm variables in whatever section is current (it has only .text/.data
and for DEC assembler rodata).

The following patch fixes that by putting it always into data section, and
additionally avoids emitting an empty line in the assembly for the lcomm
vars.

2020-03-11  Jakub Jelinek  <jakub@redhat.com>

PR target/94134
* config/pdp11/pdp11.c (pdp11_asm_output_var): Call switch_to_section
at the start to switch to data section.  Don't print extra newline if
.globl directive has not been emitted.

* gcc.c-torture/execute/pr94134.c: New test.

gcc/ChangeLog
gcc/config/pdp11/pdp11.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr94134.c [new file with mode: 0644]

index 441a0111bc4405e5bc92af138c5c0d0de4e68753..57f959604f6b8e07b3c86f63308b4bfef800ee85 100644 (file)
@@ -3,6 +3,11 @@
        Backported from mainline
        2020-03-11  Jakub Jelinek  <jakub@redhat.com>
 
+       PR target/94134
+       * config/pdp11/pdp11.c (pdp11_asm_output_var): Call switch_to_section
+       at the start to switch to data section.  Don't print extra newline if
+       .globl directive has not been emitted.
+
        PR target/94121
        * config/aarch64/aarch64.c (aarch64_add_offset_1): Use absu_hwi
        instead of abs_hwi, change moffset type to unsigned HOST_WIDE_INT.
index 5f530a4300084c781f5dfa5e3fea93a59532490e..1be79e1964c1b115794f60e670c2e44411a74b84 100644 (file)
@@ -744,6 +744,7 @@ void
 pdp11_asm_output_var (FILE *file, const char *name, int size,
                      int align, bool global)
 {
+  switch_to_section (data_section);
   if (align > 8)
     fprintf (file, "\t.even\n");
   if (TARGET_DEC_ASM)
@@ -764,8 +765,8 @@ pdp11_asm_output_var (FILE *file, const char *name, int size,
        {
          fprintf (file, ".globl ");
          assemble_name (file, name);
+         fprintf (file, "\n");
        }
-      fprintf (file, "\n");
       assemble_name (file, name);
       fputs (":", file);
       ASM_OUTPUT_SKIP (file, size);
index 685aa5718f60168ee972eddf8d372bd27ff79291..b2ae72c3c0c252800bcfd073f249534f98d8c599 100644 (file)
@@ -3,6 +3,9 @@
        Backported from mainline
        2020-03-11  Jakub Jelinek  <jakub@redhat.com>
 
+       PR target/94134
+       * gcc.c-torture/execute/pr94134.c: New test.
+
        PR target/94121
        * gcc.dg/pr94121.c: New test.
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr94134.c b/gcc/testsuite/gcc.c-torture/execute/pr94134.c
new file mode 100644 (file)
index 0000000..b1b44c3
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR target/94134 */
+
+static volatile int a = 0;
+static volatile int b = 1;
+
+int
+main ()
+{
+  a++;
+  b++;
+  if (a != 1 || b != 2)
+    __builtin_abort ();
+  return 0;
+}