public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/22] ELF: correct handling of simplified section directives
@ 2023-12-15 11:59 Jan Beulich
  2023-12-15 12:06 ` [PATCH 01/22] Arm: drop .bss override Jan Beulich
                   ` (22 more replies)
  0 siblings, 23 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 11:59 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

Various targets override .bss (many), .text, or .data (a few) handling,
and sadly more often than not these overrides break things: In some
cases .previous doesn't work as intended, while in other cases the
sub-section specifier that ELF allows also for .bss for isn't recognized.
Fix this (first primarily for .bss, then for .text/.data), putting in
place tests to cover these pretty universal ELF aspects.

Speaking of "universal ELF aspects": Three targets (csky, mcore, and
spu) handle .bss much like .lcomm. There surely are reasons for this,
but it feels at best odd.

01: Arm: drop .bss override
02: Arm64: drop .bss override
03: RISC-V: drop .bss override
04: IA64: drop .bss override
05: bfin: drop .bss override
06: m32c: drop .bss override
07: m68k: drop .bss override
08: microblaze: drop/restrict override of .text, .data, and .bss
09: rl78: drop .bss override
10: rx: drop .bss override
11: s390: drop .bss override
12: score: drop .bss override
13: visium: drop .bss and .skip overrides
14: z80: drop .bss override
15: ELF: test certain .bss usages
16: v850: drop .bss override
17: gas: correct .bss documentation for non-ELF
18: d30v: fix .text/.data interaction with .previous
19: hppa/ELF: fix .text/.data interaction with .previous
20: nios2: fix .text/.data interaction with .previous
21: pru: fix .text/.data interaction with .previous
22: ELF: test certain .text/.data usages

Jan

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 01/22] Arm: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
@ 2023-12-15 12:06 ` Jan Beulich
  2023-12-15 12:06 ` [PATCH 02/22] Arm64: " Jan Beulich
                   ` (21 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:06 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra, ramana.radhakrishnan, Richard Earnshaw

The comment looks bogus (perhaps simply stale), and there are also no
other precautions against subsections being used on ELF with .bss. It
also doesn't look to be a good idea to override the custom handlers that
ELF and COFF have (afaict doing so further broke .previous on ELF).

--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -3347,20 +3347,7 @@ s_syntax (int unused ATTRIBUTE_UNUSED)
   demand_empty_rest_of_line ();
 }
 
-/* Directives: sectioning and alignment.  */
-
-static void
-s_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  /* We don't support putting frags in the BSS segment, we fake it by
-     marking in_bss, then looking at s_skip for clues.	*/
-  subseg_set (bss_section, 0);
-  demand_empty_rest_of_line ();
-
-#ifdef md_elf_section_change_hook
-  md_elf_section_change_hook ();
-#endif
-}
+/* Directives: alignment.  */
 
 static void
 s_even (int ignore ATTRIBUTE_UNUSED)
@@ -5187,7 +5174,6 @@ const pseudo_typeS md_pseudo_table[] =
   { "dn",	   s_dn,          0 },
   { "qn",          s_qn,          0 },
   { "unreq",	   s_unreq,	  0 },
-  { "bss",	   s_bss,	  0 },
   { "align",	   s_align_ptwo,  2 },
   { "arm",	   s_arm,	  0 },
   { "thumb",	   s_thumb,	  0 },
--- a/gas/doc/c-arm.texi
+++ b/gas/doc/c-arm.texi
@@ -870,11 +870,6 @@ incrementally to the architecture being
 This performs the same action as @var{.code 32}.
 
 @c BBBBBBBBBBBBBBBBBBBBBBBBBB
-
-@cindex @code{.bss} directive, ARM
-@item .bss
-This directive switches to the @code{.bss} section.
-
 @c CCCCCCCCCCCCCCCCCCCCCCCCCC
 
 @cindex @code{.cantunwind} directive, ARM


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 02/22] Arm64: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
  2023-12-15 12:06 ` [PATCH 01/22] Arm: drop .bss override Jan Beulich
@ 2023-12-15 12:06 ` Jan Beulich
  2023-12-15 12:07 ` [PATCH 03/22] RISC-V: " Jan Beulich
                   ` (20 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:06 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra, Richard Earnshaw, Marcus Shawcroft

The comment looks bogus (perhaps simply stale, perhaps wrongly copied
from Arm in the first place), and there are also no other precautions
against subsections being used on ELF with .bss. It also doesn't look
to be a good idea to override the custom handlers that ELF and COFF
have (afaict doing so further broke .previous on ELF).

As to the mapping state update - such also doesn't appear to be done
for other section switching, so its original purpose was at best
questionable as well.

--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -1866,17 +1866,7 @@ mapping_state_2 (enum mstate state, int
 #define mapping_state_2(x, y)	/* nothing */
 #endif
 
-/* Directives: sectioning and alignment.  */
-
-static void
-s_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  /* We don't support putting frags in the BSS segment, we fake it by
-     marking in_bss, then looking at s_skip for clues.  */
-  subseg_set (bss_section, 0);
-  demand_empty_rest_of_line ();
-  mapping_state (MAP_DATA);
-}
+/* Directives: alignment.  */
 
 static void
 s_even (int ignore ATTRIBUTE_UNUSED)
@@ -2396,7 +2386,6 @@ const pseudo_typeS md_pseudo_table[] = {
   /* Never called because '.req' does not start a line.  */
   {"req", s_req, 0},
   {"unreq", s_unreq, 0},
-  {"bss", s_bss, 0},
   {"even", s_even, 0},
   {"ltorg", s_ltorg, 0},
   {"pool", s_ltorg, 0},
--- a/gas/doc/c-aarch64.texi
+++ b/gas/doc/c-aarch64.texi
@@ -389,11 +389,6 @@ extensions by the @option{-mcpu} command
 incrementally to the architecture being compiled for.
 
 @c BBBBBBBBBBBBBBBBBBBBBBBBBB
-
-@cindex @code{.bss} directive, AArch64
-@item .bss
-This directive switches to the @code{.bss} section.
-
 @c CCCCCCCCCCCCCCCCCCCCCCCCCC
 
 @cindex @code{.cpu} directive, AArch64


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 03/22] RISC-V: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
  2023-12-15 12:06 ` [PATCH 01/22] Arm: drop .bss override Jan Beulich
  2023-12-15 12:06 ` [PATCH 02/22] Arm64: " Jan Beulich
@ 2023-12-15 12:07 ` Jan Beulich
  2023-12-21  6:44   ` Nelson Chu
  2023-12-15 12:08 ` [PATCH 04/22] IA64: " Jan Beulich
                   ` (19 subsequent siblings)
  22 siblings, 1 reply; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:07 UTC (permalink / raw)
  To: Binutils
  Cc: Nick Clifton, Alan Modra, Palmer Dabbelt, Andrew Waterman,
	Jim Wilson, Nelson Chu

It doesn't look to be a good idea to override the custom handler that
ELF has; afaict doing so broke .previous, and a sub-section specifier
wasn't accepted either.

--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -4471,15 +4471,6 @@ s_dtprel (int bytes)
   demand_empty_rest_of_line ();
 }
 
-/* Handle the .bss pseudo-op.  */
-
-static void
-s_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  subseg_set (bss_section, 0);
-  demand_empty_rest_of_line ();
-}
-
 static void
 riscv_make_nops (char *buf, bfd_vma bytes)
 {
@@ -5202,7 +5193,6 @@ static const pseudo_typeS riscv_pseudo_t
   {"dword", cons, 8},
   {"dtprelword", s_dtprel, 4},
   {"dtpreldword", s_dtprel, 8},
-  {"bss", s_bss, 0},
   {"uleb128", s_riscv_leb128, 0},
   {"sleb128", s_riscv_leb128, 1},
   {"insn", s_riscv_insn, 0},
--- a/gas/doc/c-riscv.texi
+++ b/gas/doc/c-riscv.texi
@@ -138,10 +138,6 @@ Emits a DTP-relative word (or double-wor
 meant to be used by the compiler in shared libraries for DWARF debug info for
 thread local variables.
 
-@cindex BSS directive
-@item .bss
-Sets the current section to the BSS section.
-
 @cindex LEB128 directives
 @item .uleb128 @var{value}
 @itemx .sleb128 @var{value}


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 04/22] IA64: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (2 preceding siblings ...)
  2023-12-15 12:07 ` [PATCH 03/22] RISC-V: " Jan Beulich
@ 2023-12-15 12:08 ` Jan Beulich
  2023-12-15 12:09 ` [PATCH 05/22] bfin: " Jan Beulich
                   ` (18 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:08 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra, Jim Wilson

It doesn't look to be a good idea to override the custom handlers that
ELF and COFF have. While in this case interaction with ELF's .previous
wasn't screwed, the sub-section specifier wasn't permitted.

--- a/gas/config/tc-ia64.c
+++ b/gas/config/tc-ia64.c
@@ -68,8 +68,7 @@
 enum special_section
   {
     /* IA-64 ABI section pseudo-ops.  */
-    SPECIAL_SECTION_BSS = 0,
-    SPECIAL_SECTION_SBSS,
+    SPECIAL_SECTION_SBSS = 0,
     SPECIAL_SECTION_SDATA,
     SPECIAL_SECTION_RODATA,
     SPECIAL_SECTION_COMMENT,
@@ -645,7 +644,7 @@ static const bfd_vma nop[IA64_NUM_UNITS]
    habit of setting temporary sentinels.  */
 static char special_section_name[][20] =
   {
-    {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
+    {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
     {".IA_64.unwind"}, {".IA_64.unwind_info"},
     {".init_array"}, {".fini_array"}
   };
@@ -3172,7 +3171,7 @@ dot_loc (int x)
   dwarf2_directive_loc (x);
 }
 
-/* .sbss, .bss etc. are macros that expand into ".section SECNAME".  */
+/* .sbss, .srodata etc. are macros that expand into ".section SECNAME".  */
 static void
 dot_special_section (int which)
 {
@@ -5201,7 +5200,6 @@ const pseudo_typeS md_pseudo_table[] =
     { "radix", dot_radix, 0 },
     { "lcomm", s_lcomm_bytes, 1 },
     { "loc", dot_loc, 0 },
-    { "bss", dot_special_section, SPECIAL_SECTION_BSS },
     { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
     { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
     { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 05/22] bfin: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (3 preceding siblings ...)
  2023-12-15 12:08 ` [PATCH 04/22] IA64: " Jan Beulich
@ 2023-12-15 12:09 ` Jan Beulich
  2023-12-15 12:10 ` [PATCH 06/22] m32c: " Jan Beulich
                   ` (17 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:09 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra, Jie Zhang, Mike Frysinger

It doesn't look to be a good idea to override the custom handler that
ELF has; afaict doing so broke .previous.

--- a/gas/config/tc-bfin.c
+++ b/gas/config/tc-bfin.c
@@ -106,16 +106,6 @@ bfin_pic_ptr (int nbytes)
   demand_empty_rest_of_line ();
 }
 
-static void
-bfin_s_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  int temp;
-
-  temp = get_absolute_expression ();
-  subseg_set (bss_section, (subsegT) temp);
-  demand_empty_rest_of_line ();
-}
-
 const pseudo_typeS md_pseudo_table[] = {
   {"align", s_align_bytes, 0},
   {"byte2", cons, 2},
@@ -128,7 +118,6 @@ const pseudo_typeS md_pseudo_table[] = {
   {"p", s_ignore, 0},
   {"pdata", s_ignore, 0},
   {"var", s_ignore, 0},
-  {"bss", bfin_s_bss, 0},
   {0, 0, 0}
 };
 


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 06/22] m32c: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (4 preceding siblings ...)
  2023-12-15 12:09 ` [PATCH 05/22] bfin: " Jan Beulich
@ 2023-12-15 12:10 ` Jan Beulich
  2023-12-15 12:10 ` [PATCH 07/22] m68k: " Jan Beulich
                   ` (16 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:10 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

It doesn't look to be a good idea to override the custom handler that
ELF has; afaict doing so broke .previous.

--- a/gas/config/tc-m32c.c
+++ b/gas/config/tc-m32c.c
@@ -100,8 +100,6 @@ set_isa (enum isa_attr isa_num)
   cgen_bitset_set (& m32c_isa, isa_num);
 }
 
-static void s_bss (int);
-
 int
 md_parse_option (int c, const char * arg ATTRIBUTE_UNUSED)
 {
@@ -141,20 +139,9 @@ md_show_usage (FILE * stream)
   fprintf (stream, _(" M32C specific command line options:\n"));
 }
 
-static void
-s_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  int temp;
-
-  temp = get_absolute_expression ();
-  subseg_set (bss_section, (subsegT) temp);
-  demand_empty_rest_of_line ();
-}
-
 /* The target specific pseudo-ops which we support.  */
 const pseudo_typeS md_pseudo_table[] =
 {
-  { "bss",	s_bss, 		0},
   { "3byte",	cons,		3 },
   { "word",	cons,		4 },
   { NULL, 	NULL, 		0 }


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 07/22] m68k: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (5 preceding siblings ...)
  2023-12-15 12:10 ` [PATCH 06/22] m32c: " Jan Beulich
@ 2023-12-15 12:10 ` Jan Beulich
  2023-12-15 12:11 ` [PATCH 08/22] microblaze: drop/restrict override of .text, .data, and .bss Jan Beulich
                   ` (15 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:10 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

The comment looks bogus (perhaps simply stale), and there are also no
other precautions against subsections being used on ELF with .bss. It
also doesn't look to be a good idea to override the custom handler that
ELF has (afaict doing so further broke .previous).

--- a/gas/config/tc-m68k.c
+++ b/gas/config/tc-m68k.c
@@ -455,7 +455,6 @@ static int reverse_16_bits (int in);
 static int reverse_8_bits (int in);
 static void install_gen_operand (int mode, int val);
 static void install_operand (int mode, int val);
-static void s_bss (int);
 static void s_data1 (int);
 static void s_data2 (int);
 static void s_even (int);
@@ -862,7 +861,6 @@ const pseudo_typeS md_pseudo_table[] =
 {
   {"data1", s_data1, 0},
   {"data2", s_data2, 0},
-  {"bss", s_bss, 0},
   {"even", s_even, 0},
   {"skip", s_space, 0},
   {"proc", s_proc, 0},
@@ -5493,16 +5491,6 @@ s_data2 (int ignore ATTRIBUTE_UNUSED)
   demand_empty_rest_of_line ();
 }
 
-static void
-s_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  /* We don't support putting frags in the BSS segment, we fake it
-     by marking in_bss, then looking at s_skip for clues.  */
-
-  subseg_set (bss_section, 0);
-  demand_empty_rest_of_line ();
-}
-
 static void
 s_even (int ignore ATTRIBUTE_UNUSED)
 {


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 08/22] microblaze: drop/restrict override of .text, .data, and .bss
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (6 preceding siblings ...)
  2023-12-15 12:10 ` [PATCH 07/22] m68k: " Jan Beulich
@ 2023-12-15 12:11 ` Jan Beulich
  2023-12-15 12:12 ` [PATCH 09/22] rl78: drop .bss override Jan Beulich
                   ` (14 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:11 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra, Michael Eager

While only ELF is supported right now, (stub) code generally is in place
for the non-ELF case as well. Don't override .bss for ELF - that's
unlikely to be a good idea anyway and prevented the sub-section
specifier from being usable. Don't override .text and .data at all - for
.data and ELF for the same reason, while for .text and ELF obj-elf.c's is
all we need, and for (hypothetical) non-ELF read.c's identical handling
would have been invoked anyway.
---
Wiring .bss to s_data() is somewhat odd, too.

--- a/gas/config/tc-microblaze.c
+++ b/gas/config/tc-microblaze.c
@@ -135,27 +135,6 @@ microblaze_generate_symbol (char *sym)
 
 /* Handle the section changing pseudo-ops. */
 
-static void
-microblaze_s_text (int ignore ATTRIBUTE_UNUSED)
-{
-#ifdef OBJ_ELF
-  obj_elf_text (ignore);
-#else
-  s_text (ignore);
-#endif
-}
-
-static void
-microblaze_s_data (int ignore ATTRIBUTE_UNUSED)
-{
-#ifdef OBJ_ELF
-  obj_elf_change_section (".data", SHT_PROGBITS, SHF_ALLOC+SHF_WRITE,
-			  0, 0, false);
-#else
-  s_data (ignore);
-#endif
-}
-
 /* Things in the .sdata segment are always considered to be in the small data section.  */
 
 static void
@@ -298,20 +277,13 @@ microblaze_s_rdata (int localvar)
 }
 
 static void
-microblaze_s_bss (int localvar)
+microblaze_s_sbss (int ignore ATTRIBUTE_UNUSED)
 {
 #ifdef OBJ_ELF
-  if (localvar == 0) /* bss.  */
-    obj_elf_change_section (".bss", SHT_NOBITS, SHF_ALLOC+SHF_WRITE,
-			    0, 0, false);
-  else if (localvar == 1)
-    {
-      /* sbss.  */
-      obj_elf_change_section (".sbss", SHT_NOBITS, SHF_ALLOC+SHF_WRITE,
-			      0, 0, false);
-      if (sbss_segment == 0)
-	sbss_segment = subseg_new (".sbss", 0);
-    }
+  obj_elf_change_section (".sbss", SHT_NOBITS, SHF_ALLOC+SHF_WRITE,
+			  0, 0, false);
+  if (sbss_segment == 0)
+    sbss_segment = subseg_new (".sbss", 0);
 #else
   s_data (ignore);
 #endif
@@ -385,7 +357,6 @@ microblaze_s_weakext (int ignore ATTRIBU
 const pseudo_typeS md_pseudo_table[] =
 {
   {"lcomm", microblaze_s_lcomm, 1},
-  {"data", microblaze_s_data, 0},
   {"data8", cons, 1},      /* Same as byte.  */
   {"data16", cons, 2},     /* Same as hword.  */
   {"data32", cons, 4},     /* Same as word.  */
@@ -396,9 +367,10 @@ const pseudo_typeS md_pseudo_table[] =
   {"rodata", microblaze_s_rdata, 0},
   {"sdata2", microblaze_s_rdata, 1},
   {"sdata", microblaze_s_sdata, 0},
-  {"bss", microblaze_s_bss, 0},
-  {"sbss", microblaze_s_bss, 1},
-  {"text", microblaze_s_text, 0},
+#ifndef OBJ_ELF
+  {"bss", s_data, 0},
+#endif
+  {"sbss", microblaze_s_sbss, 0},
   {"word", cons, 4},
   {"frame", s_ignore, 0},
   {"mask", s_ignore, 0}, /* Emitted by gcc.  */


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 09/22] rl78: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (7 preceding siblings ...)
  2023-12-15 12:11 ` [PATCH 08/22] microblaze: drop/restrict override of .text, .data, and .bss Jan Beulich
@ 2023-12-15 12:12 ` Jan Beulich
  2023-12-15 12:12 ` [PATCH 10/22] rx: " Jan Beulich
                   ` (13 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:12 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

It doesn't look to be a good idea to override the custom handler that
ELF has; afaict doing so broke .previous.

--- a/gas/config/tc-rl78.c
+++ b/gas/config/tc-rl78.c
@@ -375,16 +375,6 @@ md_show_usage (FILE * stream)
 }
 
 static void
-s_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  int temp;
-
-  temp = get_absolute_expression ();
-  subseg_set (bss_section, (subsegT) temp);
-  demand_empty_rest_of_line ();
-}
-
-static void
 rl78_float_cons (int ignore ATTRIBUTE_UNUSED)
 {
   if (elf_flags & E_FLAG_RL78_64BIT_DOUBLES)
@@ -397,7 +387,6 @@ const pseudo_typeS md_pseudo_table[] =
 {
   /* Our "standard" pseudos.  */
   { "double", rl78_float_cons,	'd' },
-  { "bss",    s_bss, 		0 },
   { "3byte",  cons,		3 },
   { "int",    cons,		4 },
   { "word",   cons,		4 },


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 10/22] rx: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (8 preceding siblings ...)
  2023-12-15 12:12 ` [PATCH 09/22] rl78: drop .bss override Jan Beulich
@ 2023-12-15 12:12 ` Jan Beulich
  2023-12-15 12:13 ` [PATCH 11/22] s390: " Jan Beulich
                   ` (12 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:12 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

It doesn't look to be a good idea to override the custom handler that
ELF has; afaict doing so broke .previous.

--- a/gas/config/tc-rx.c
+++ b/gas/config/tc-rx.c
@@ -222,16 +222,6 @@ md_show_usage (FILE * stream)
 }
 
 static void
-s_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  int temp;
-
-  temp = get_absolute_expression ();
-  subseg_set (bss_section, (subsegT) temp);
-  demand_empty_rest_of_line ();
-}
-
-static void
 rx_float_cons (int ignore ATTRIBUTE_UNUSED)
 {
   if (elf_flags & E_FLAG_RX_64BIT_DOUBLES)
@@ -650,7 +640,6 @@ const pseudo_typeS md_pseudo_table[] =
 
   /* Our "standard" pseudos. */
   { "double",   rx_float_cons,  0 },
-  { "bss",	s_bss, 		0 },
   { "3byte",	cons,		3 },
   { "int",	cons,		4 },
   { "word",	cons,		4 },


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 11/22] s390: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (9 preceding siblings ...)
  2023-12-15 12:12 ` [PATCH 10/22] rx: " Jan Beulich
@ 2023-12-15 12:13 ` Jan Beulich
  2023-12-15 12:14 ` [PATCH 12/22] score: " Jan Beulich
                   ` (11 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:13 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra, Andreas Krebbel

The comment looks bogus (perhaps simply stale), and there are also no
other precautions against subsections being used on ELF with .bss. It
also doesn't look to be a good idea to override the custom handler that
ELF has (afaict doing so further broke .previous).

--- a/gas/config/tc-s390.c
+++ b/gas/config/tc-s390.c
@@ -88,7 +88,6 @@ int s390_cie_data_alignment;
 /* Define the prototypes for the pseudo-ops */
 static void s390_byte (int);
 static void s390_elf_cons (int);
-static void s390_bss (int);
 static void s390_insn (int);
 static void s390_literals (int);
 static void s390_machine (int);
@@ -98,7 +97,6 @@ const pseudo_typeS md_pseudo_table[] =
 {
   { "align",        s_align_bytes,      0 },
   /* Pseudo-ops which must be defined.  */
-  { "bss",          s390_bss,           0 },
   { "insn",         s390_insn,          0 },
   /* Pseudo-ops which must be overridden.  */
   { "byte",	    s390_byte,	        0 },
@@ -1734,16 +1732,6 @@ md_create_long_jump (ptr, from_addr, to_
 }
 #endif
 
-void
-s390_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  /* We don't support putting frags in the BSS segment, we fake it
-     by marking in_bss, then looking at s_skip for clues.  */
-
-  subseg_set (bss_section, 0);
-  demand_empty_rest_of_line ();
-}
-
 /* Pseudo-op handling.  */
 
 void


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 12/22] score: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (10 preceding siblings ...)
  2023-12-15 12:13 ` [PATCH 11/22] s390: " Jan Beulich
@ 2023-12-15 12:14 ` Jan Beulich
  2023-12-15 12:15 ` [PATCH 13/22] visium: drop .bss and .skip overrides Jan Beulich
                   ` (10 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:14 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

The comment looks bogus (perhaps simply stale, or wrongly copied from
another target). It also doesn't look to be a good idea to override the
custom handler that ELF has (afaict doing so broke .previous as well as
sub-section specification).

While there also fold the identical handlers for .text (there likely is
more room for such folding).

--- a/gas/config/tc-score.c
+++ b/gas/config/tc-score.c
@@ -24,8 +24,6 @@
 
 #include "tc-score7.c"
 
-static void s3_s_score_bss (int ignore ATTRIBUTE_UNUSED);
-static void s3_s_score_text (int ignore);
 static void s3_score_s_section (int ignore);
 static void s3_s_change_sec (int sec);
 static void s3_s_score_mask (int reg_type ATTRIBUTE_UNUSED);
@@ -39,7 +37,6 @@ static void s3_s_score_gpword (int ignor
 static void s3_s_score_cpadd (int ignore ATTRIBUTE_UNUSED);
 static void s3_s_score_lcomm (int bytes_p);
 
-static void s_score_bss (int ignore ATTRIBUTE_UNUSED);
 static void s_score_text (int ignore);
 static void s_section (int ignore);
 static void s_change_sec (int sec);
@@ -196,7 +193,6 @@ symbolS *GOT_symbol;
 
 const pseudo_typeS md_pseudo_table[] =
 {
-  {"bss", s_score_bss, 0},
   {"text", s_score_text, 0},
   {"word", cons, 4},
   {"long", cons, 4},
@@ -5532,22 +5528,6 @@ s3_do_dsp3 (char *str)
     s3_inst.relax_inst = 0x8000;
 }
 
-
-/* If we change section we must dump the literal pool first.  */
-static void
-s3_s_score_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  subseg_set (bss_section, (subsegT) get_absolute_expression ());
-  demand_empty_rest_of_line ();
-}
-
-static void
-s3_s_score_text (int ignore)
-{
-  obj_elf_text (ignore);
-  record_alignment (now_seg, 2);
-}
-
 static void
 s3_score_s_section (int ignore)
 {
@@ -6324,21 +6304,10 @@ s3_build_dependency_insn_hsh (void)
 }
 
 static void
-s_score_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  if (score3)
-    return s3_s_score_bss (ignore);
-  else
-    return s7_s_score_bss (ignore);
-}
-
-static void
 s_score_text (int ignore)
 {
-  if (score3)
-    return s3_s_score_text (ignore);
-  else
-    return s7_s_score_text (ignore);
+  obj_elf_text (ignore);
+  record_alignment (now_seg, 2);
 }
 
 static void
--- a/gas/config/tc-score7.c
+++ b/gas/config/tc-score7.c
@@ -5367,21 +5367,6 @@ s7_build_reg_hsh (struct s7_reg_map *map
 
 \f
 
-/* If we change section we must dump the literal pool first.  */
-static void
-s7_s_score_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  subseg_set (bss_section, (subsegT) get_absolute_expression ());
-  demand_empty_rest_of_line ();
-}
-
-static void
-s7_s_score_text (int ignore)
-{
-  obj_elf_text (ignore);
-  record_alignment (now_seg, 2);
-}
-
 static void
 s7_s_section (int ignore)
 {


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 13/22] visium: drop .bss and .skip overrides
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (11 preceding siblings ...)
  2023-12-15 12:14 ` [PATCH 12/22] score: " Jan Beulich
@ 2023-12-15 12:15 ` Jan Beulich
  2023-12-15 12:16 ` [PATCH 14/22] z80: drop .bss override Jan Beulich
                   ` (9 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:15 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra, Eric Botcazou

The comment in s_bss() looks bogus (perhaps simply stale, or wrongly
copied from another target). It also doesn't look to be a good idea to
override the custom handler that ELF has (afaict doing so broke
.previous as well as sub-section specification).

The override for .skip is simply pointless, for read.c having exactly
the same.

While there also drop two adjacent redundant (with read.h) declarations
(which would be outright dangerous if read.h wasn't included anyway).

--- a/gas/config/tc-visium.c
+++ b/gas/config/tc-visium.c
@@ -163,40 +163,19 @@ tc_gen_reloc (asection *section ATTRIBUT
   return reloc;
 }
 
-extern char *input_line_pointer;
-
-
-static void s_bss (int);
 static void visium_rdata (int);
 
 static void visium_update_parity_bit (char *);
 static char *parse_exp (char *, expressionS *);
 
-/* These are the back-ends for the various machine dependent pseudo-ops.  */
-void demand_empty_rest_of_line (void);
-
-
-static void
-s_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  /* We don't support putting frags in the BSS segment, we fake it
-     by marking in_bss, then looking at s_skip for clues.  */
-
-  subseg_set (bss_section, 0);
-  demand_empty_rest_of_line ();
-}
-
-
 /* This table describes all the machine specific pseudo-ops the assembler
-   has to support. The fields are:
+   has to support, and that aren't handled elsewhere. The fields are:
 
    1: Pseudo-op name without dot.
    2: Function to call to execute this pseudo-op.
    3: Integer arg to pass to the function.  */
 const pseudo_typeS md_pseudo_table[] =
 {
-  {"bss", s_bss, 0},
-  {"skip", s_space, 0},
   {"align", s_align_bytes, 0},
   {"noopt", s_ignore, 0},
   {"optim", s_ignore, 0},


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 14/22] z80: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (12 preceding siblings ...)
  2023-12-15 12:15 ` [PATCH 13/22] visium: drop .bss and .skip overrides Jan Beulich
@ 2023-12-15 12:16 ` Jan Beulich
  2023-12-15 12:16 ` [PATCH 15/22] ELF: test certain .bss usages Jan Beulich
                   ` (8 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:16 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

It doesn't look to be a good idea to override the custom handlers that
ELF and COFF have; afaict doing so broke .previous on ELF, and a sub-
section specifier wasn't accepted either.

--- a/gas/config/tc-z80.c
+++ b/gas/config/tc-z80.c
@@ -3483,15 +3483,6 @@ area (int arg)
     psect (arg);
 }
 
-/* Handle the .bss pseudo-op.  */
-
-static void
-s_bss (int ignore ATTRIBUTE_UNUSED)
-{
-  subseg_set (bss_section, 0);
-  demand_empty_rest_of_line ();
-}
-
 /* Port specific pseudo ops.  */
 const pseudo_typeS md_pseudo_table[] =
 {
@@ -3507,7 +3498,6 @@ const pseudo_typeS md_pseudo_table[] =
   { ".hd64", set_inss, INS_Z180},
   { ".z80", set_inss, INS_Z80},
   { ".z80n", set_inss, INS_Z80N},
-  { "bss", s_bss, 0},
   { "db" , emit_data, 1},
   { "d24", z80_cons, 3},
   { "d32", z80_cons, 4},


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 15/22] ELF: test certain .bss usages
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (13 preceding siblings ...)
  2023-12-15 12:16 ` [PATCH 14/22] z80: drop .bss override Jan Beulich
@ 2023-12-15 12:16 ` Jan Beulich
  2023-12-15 12:16 ` [PATCH 16/22] gas: correct .bss documentation for non-ELF Jan Beulich
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:16 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

Various targets have / had overrides for .bss. Make sure that in such
cases
- .previous still works correctly (requiring such targets to invoke
  obj_elf_section_change_hook() from their overriding handlers),
- sub-section specifiers are accepted as far as feasible (mandated by
  the doc).

--- /dev/null
+++ b/gas/testsuite/gas/elf/bss-prev.d
@@ -0,0 +1,13 @@
+#name: .bss / .previous interaction
+#as: --no-pad-sections
+#readelf: -S --wide
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Addr(ess|) +Off +Size .*
+#...
+ *\[ [1-9]\] *\.text +PROGBITS +0*0 +0[0-9a-f]* 0+ .*
+ *\[ [1-9]\] *\.data +PROGBITS +0*0 +0[0-9a-f]* 0*1 .*
+ *\[ [1-9]\] *\.bss +NOBITS +0*0 +0[0-9a-f]* 0*1 .*
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/elf/bss-prev.s
@@ -0,0 +1,6 @@
+	.text
+	.data
+	.bss
+	.byte 0
+	.previous
+	.byte 1
--- /dev/null
+++ b/gas/testsuite/gas/elf/bss-subsect.d
@@ -0,0 +1,11 @@
+#name: .bss <subsection>
+#as: --no-pad-sections
+#readelf: -S --wide
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Addr(ess|) +Off +Size .*
+#...
+ *\[ [1-9]\] *\.bss +NOBITS +0*0 +0[0-9a-f]* 0*a .*
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/elf/bss-subsect.s
@@ -0,0 +1,10 @@
+	.bss
+	.byte 0
+
+	.bss 2
+	.balign 2
+	.skip 2
+
+	.bss 1
+	.balign 4
+	.skip 4
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -336,6 +336,13 @@ if { [is_elf_format] } then {
 
     run_dump_test "pr25917"
     run_dump_test "bss"
+    # Some targets treat .bss similar to .lcomm.
+    if { ![istarget "csky-*-*"]
+	 && ![istarget "mcore-*-*"]
+	 && ![istarget "spu-*-*"] } then {
+	run_dump_test "bss-prev" $dump_opts
+	run_dump_test "bss-subsect" $dump_opts
+    }
     run_dump_test "bad-bss"
     run_dump_test "bad-section-flag"
     run_dump_test "bad-size"


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 16/22] gas: correct .bss documentation for non-ELF
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (14 preceding siblings ...)
  2023-12-15 12:16 ` [PATCH 15/22] ELF: test certain .bss usages Jan Beulich
@ 2023-12-15 12:16 ` Jan Beulich
  2023-12-15 12:17 ` [PATCH 17/22] v850: drop .bss override Jan Beulich
                   ` (6 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:16 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

Only ELF permits the specification of a subsection, and even there not
consistently: csky, mcore, and spu handle .bss similar to .lcomm.
---
Except for H8 this doesn't look to have any effect, because all.texi
blindly enables various object formats. Yet still the documentation ends
up wrong for non-ELF targets.
---
v1: Mention exceptions.

--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -4456,7 +4456,12 @@ Some machine configurations provide addi
 * Asciz::                       @code{.asciz "@var{string}"}@dots{}
 * Attach_to_group::             @code{.attach_to_group @var{name}}
 * Balign::                      @code{.balign [@var{abs-expr}[, @var{abs-expr}]]}
+@ifset ELF
 * Bss::                         @code{.bss @var{subsection}}
+@end ifset
+@ifclear ELF
+* Bss::                         @code{.bss}
+@end ifclear
 * Bundle directives::           @code{.bundle_align_mode @var{abs-expr}}, etc
 * Byte::                        @code{.byte @var{expressions}}
 * CFI directives::		@code{.cfi_startproc [simple]}, @code{.cfi_endproc}, etc.
@@ -4801,14 +4806,20 @@ filled in with the value 0x368d (the exa
 the endianness of the processor).  If it skips 1 or 3 bytes, the fill value is
 undefined.
 
+@ifset ELF
 @node Bss
 @section @code{.bss @var{subsection}}
+@end ifset
+@ifclear ELF
+@node Bss
+@section @code{.bss}
+@end ifclear
 @cindex @code{bss} directive
 
 @code{.bss} tells @command{@value{AS}} to assemble the following statements
 onto the end of the bss section.
 @ifset ELF
-For ELF based targets an optional @var{subsection} expression (which must
+For most ELF based targets an optional @var{subsection} expression (which must
 evaluate to a positive integer) can be provided.  In this case the statements
 are appended to the end of the indicated bss subsection.
 @end ifset


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 17/22] v850: drop .bss override
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (15 preceding siblings ...)
  2023-12-15 12:16 ` [PATCH 16/22] gas: correct .bss documentation for non-ELF Jan Beulich
@ 2023-12-15 12:17 ` Jan Beulich
  2023-12-15 12:18 ` [PATCH 18/22] d30v: fix .text/.data interaction with .previous Jan Beulich
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:17 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

While there doesn't look to be anything wrong with this override,
there's also no apparent reason why this override would be needed. Drop
it, reducing overall size a tiny bit.

--- a/gas/config/tc-v850.c
+++ b/gas/config/tc-v850.c
@@ -198,8 +198,6 @@ struct v850_seg_entry v850_seg_table[] =
   { NULL, ".call_table_text",
     SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY | SEC_CODE
     | SEC_HAS_CONTENTS},
-  { NULL, ".bss",
-    SEC_ALLOC }
 };
 
 #define SDATA_SECTION		0
@@ -215,7 +213,6 @@ struct v850_seg_entry v850_seg_table[] =
 #define ZCOMMON_SECTION		10
 #define CALL_TABLE_DATA_SECTION	11
 #define CALL_TABLE_TEXT_SECTION	12
-#define BSS_SECTION		13
 
 static void
 do_v850_seg (int i, subsegT sub)
@@ -578,7 +575,6 @@ const pseudo_typeS md_pseudo_table[] =
   { "zbss",		v850_seg,		ZBSS_SECTION		},
   { "rosdata",		v850_seg,		ROSDATA_SECTION 	},
   { "rozdata",		v850_seg,		ROZDATA_SECTION 	},
-  { "bss",		v850_seg,		BSS_SECTION		},
   { "offset",		v850_offset,		0			},
   { "word",		cons,			4			},
   { "zcomm",		v850_comm,		ZCOMMON_SECTION 	},
@@ -1969,7 +1965,6 @@ md_begin (void)
       op++;
     }
 
-  v850_seg_table[BSS_SECTION].s = bss_section;
   bfd_set_arch_mach (stdoutput, v850_target_arch, machine);
   bfd_set_private_flags (stdoutput, v850_e_flags);
 }


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 18/22] d30v: fix .text/.data interaction with .previous
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (16 preceding siblings ...)
  2023-12-15 12:17 ` [PATCH 17/22] v850: drop .bss override Jan Beulich
@ 2023-12-15 12:18 ` Jan Beulich
  2023-12-15 12:19 ` [PATCH 19/22] hppa/ELF: " Jan Beulich
                   ` (4 subsequent siblings)
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:18 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

Just like obj_elf_section() is called for .section, obj_elf_{text,data}()
need calling for .text/.data.

--- a/gas/config/tc-d30v.c
+++ b/gas/config/tc-d30v.c
@@ -2055,7 +2055,7 @@ static void
 s_d30v_text (int i)
 
 {
-  s_text (i);
+  obj_elf_text (i);
   d30v_last_label = NULL;
   d30v_current_align = 0;
   d30v_current_align_seg = now_seg;
@@ -2067,7 +2067,7 @@ s_d30v_text (int i)
 static void
 s_d30v_data (int i)
 {
-  s_data (i);
+  obj_elf_data (i);
   d30v_last_label = NULL;
   d30v_current_align = 0;
   d30v_current_align_seg = now_seg;


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 19/22] hppa/ELF: fix .text/.data interaction with .previous
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (17 preceding siblings ...)
  2023-12-15 12:18 ` [PATCH 18/22] d30v: fix .text/.data interaction with .previous Jan Beulich
@ 2023-12-15 12:19 ` Jan Beulich
  2023-12-15 16:37   ` John David Anglin
  2023-12-15 12:19 ` [PATCH 20/22] nios2: " Jan Beulich
                   ` (3 subsequent siblings)
  22 siblings, 1 reply; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:19 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra, Dave Anglin, Jeff Law

For some ELF targets .text/.data are overridden. In that case
obj_elf_{text,data}() need calling, just like .code vectors to that
function for the remaining ELF targets.

While there also hand on the function arguments, even if right now
they're meaningless. This matches what other targets' code does.

--- a/gas/config/tc-hppa.c
+++ b/gas/config/tc-hppa.c
@@ -6199,7 +6199,7 @@ pa_callinfo (int unused ATTRIBUTE_UNUSED
    label when finished.  */
 
 static void
-pa_text (int unused ATTRIBUTE_UNUSED)
+pa_text (int arg)
 {
 #ifdef OBJ_SOM
   current_space = is_defined_space ("$TEXT$");
@@ -6207,21 +6207,32 @@ pa_text (int unused ATTRIBUTE_UNUSED)
     = pa_subsegment_to_subspace (current_space->sd_seg, 0);
 #endif
 
-  s_text (0);
+#ifdef OBJ_ELF
+  obj_elf_text (arg);
+#else
+  s_text (arg);
+#endif
+
   pa_undefine_label ();
 }
 
 /* Switch to the data space.  As usual delete our label.  */
 
 static void
-pa_data (int unused ATTRIBUTE_UNUSED)
+pa_data (int arg)
 {
 #ifdef OBJ_SOM
   current_space = is_defined_space ("$PRIVATE$");
   current_subspace
     = pa_subsegment_to_subspace (current_space->sd_seg, 0);
 #endif
-  s_data (0);
+
+#ifdef OBJ_ELF
+  obj_elf_data (arg);
+#else
+  s_data (arg);
+#endif
+
   pa_undefine_label ();
 }
 


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 20/22] nios2: fix .text/.data interaction with .previous
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (18 preceding siblings ...)
  2023-12-15 12:19 ` [PATCH 19/22] hppa/ELF: " Jan Beulich
@ 2023-12-15 12:19 ` Jan Beulich
  2023-12-15 19:00   ` Sandra Loosemore
  2023-12-15 12:20 ` [PATCH 21/22] pru: " Jan Beulich
                   ` (2 subsequent siblings)
  22 siblings, 1 reply; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:19 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra, Sandra Loosemore, Andrew Jenner

Just like obj_elf_section() is called for .section, obj_elf_{text,data}()
need calling for .text/.data.

--- a/gas/config/tc-nios2.c
+++ b/gas/config/tc-nios2.c
@@ -507,7 +507,7 @@ s_nios2_align (int ignore ATTRIBUTE_UNUS
 static void
 s_nios2_text (int i)
 {
-  s_text (i);
+  obj_elf_text (i);
   nios2_last_label = NULL;
   nios2_current_align = 0;
   nios2_current_align_seg = now_seg;
@@ -518,7 +518,7 @@ s_nios2_text (int i)
 static void
 s_nios2_data (int i)
 {
-  s_data (i);
+  obj_elf_data (i);
   nios2_last_label = NULL;
   nios2_current_align = 0;
   nios2_current_align_seg = now_seg;


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 21/22] pru: fix .text/.data interaction with .previous
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (19 preceding siblings ...)
  2023-12-15 12:19 ` [PATCH 20/22] nios2: " Jan Beulich
@ 2023-12-15 12:20 ` Jan Beulich
  2023-12-15 12:20 ` [PATCH 22/22] ELF: test certain .text/.data usages Jan Beulich
  2024-01-02  0:40 ` [PATCH 00/22] ELF: correct handling of simplified section directives Alan Modra
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:20 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

Just like obj_elf_section() is called for .section, obj_elf_{text,data}()
need calling for .text/.data.

--- a/gas/config/tc-pru.c
+++ b/gas/config/tc-pru.c
@@ -368,7 +368,7 @@ s_pru_align (int ignore ATTRIBUTE_UNUSED
 static void
 s_pru_text (int i)
 {
-  s_text (i);
+  obj_elf_text (i);
   pru_last_label = NULL;
   pru_current_align = 0;
   pru_current_align_seg = now_seg;
@@ -379,7 +379,7 @@ s_pru_text (int i)
 static void
 s_pru_data (int i)
 {
-  s_data (i);
+  obj_elf_data (i);
   pru_last_label = NULL;
   pru_current_align = 0;
   pru_current_align_seg = now_seg;


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 22/22] ELF: test certain .text/.data usages
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (20 preceding siblings ...)
  2023-12-15 12:20 ` [PATCH 21/22] pru: " Jan Beulich
@ 2023-12-15 12:20 ` Jan Beulich
  2024-01-02  0:40 ` [PATCH 00/22] ELF: correct handling of simplified section directives Alan Modra
  22 siblings, 0 replies; 27+ messages in thread
From: Jan Beulich @ 2023-12-15 12:20 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton, Alan Modra

Various targets have / had overrides for .text and/or .data. Make sure
that in such cases sub-section specifiers are accepted, as mandated by
the doc.

--- /dev/null
+++ b/gas/testsuite/gas/elf/data-prev.d
@@ -0,0 +1,14 @@
+#name: .data / .previous interaction
+#as: --no-pad-sections
+#readelf: -S --wide
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Addr(ess|) +Off +Size .*
+#...
+ *\[ [1-9]\] *\.text +PROGBITS +0*0 +0[0-9a-f]* 0* .*
+ *\[ [1-9]\] *\.data +PROGBITS +0*0 +0[0-9a-f]* 0*1 .*
+#...
+ *\[ [1-9]\] *\.aux +PROGBITS +0*0 +0[0-9a-f]* 0*1 .*
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/elf/data-prev.s
@@ -0,0 +1,6 @@
+	.text
+	.section .aux, "a", %progbits
+	.data
+	.byte 0
+	.previous
+	.byte 1
--- /dev/null
+++ b/gas/testsuite/gas/elf/data-subsect.d
@@ -0,0 +1,11 @@
+#name: .data <subsection>
+#as: --no-pad-sections
+#readelf: -S --wide
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Addr(ess|) +Off +Size .*
+#...
+ *\[ [1-9]\] *\.data +PROGBITS +0*0 +0[0-9a-f]* 0*a .*
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/elf/data-subsect.s
@@ -0,0 +1,14 @@
+	.data
+	.byte 1
+
+	.data 2
+	.balign 2
+	.byte 3
+	.byte 3
+
+	.data 1
+	.balign 4
+	.byte 2
+	.byte 2
+	.byte 2
+	.byte 2
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -194,6 +194,10 @@ if { [is_elf_format] } then {
 	}
     }
     run_dump_test "pseudo"
+    run_dump_test "text-prev" $dump_opts
+    run_dump_test "text-subsect" $dump_opts
+    run_dump_test "data-prev" $dump_opts
+    run_dump_test "data-subsect" $dump_opts
     run_dump_test "section0"
     run_dump_test "section1"
     # The h8300 port issues a warning message for
--- /dev/null
+++ b/gas/testsuite/gas/elf/text-prev.d
@@ -0,0 +1,14 @@
+#name: .text / .previous interaction
+#as: --no-pad-sections
+#readelf: -S --wide
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Addr(ess|) +Off +Size .*
+#...
+ *\[ [1-9]\] *\.text +PROGBITS +0*0 +0[0-9a-f]* 0*([1248]|10) .*
+ *\[ [1-9]\] *\.data +PROGBITS +0*0 +0[0-9a-f]* 0* .*
+#...
+ *\[ [1-9]\] *\.aux +PROGBITS +0*0 +0[0-9a-f]* 0*1 .*
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/elf/text-prev.s
@@ -0,0 +1,6 @@
+	.data
+	.section .aux, "a", %progbits
+	.text
+	.nop
+	.previous
+	.byte 0
--- /dev/null
+++ b/gas/testsuite/gas/elf/text-subsect.d
@@ -0,0 +1,11 @@
+#name: .text <subsection>
+#as: --no-pad-sections
+#readelf: -S --wide
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Addr(ess|) +Off +Size .*
+#...
+ *\[ [1-9]\] *\.text +PROGBITS +0*0 +0[0-9a-f]* 0*(6[1248]|70) .*
+#pass
--- /dev/null
+++ b/gas/testsuite/gas/elf/text-subsect.s
@@ -0,0 +1,10 @@
+	.text
+	.nop
+
+	.text 2
+	.balign 32
+	.nop
+
+	.text 1
+	.balign 64
+	.nop


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 19/22] hppa/ELF: fix .text/.data interaction with .previous
  2023-12-15 12:19 ` [PATCH 19/22] hppa/ELF: " Jan Beulich
@ 2023-12-15 16:37   ` John David Anglin
  0 siblings, 0 replies; 27+ messages in thread
From: John David Anglin @ 2023-12-15 16:37 UTC (permalink / raw)
  To: Jan Beulich, Binutils; +Cc: Nick Clifton, Alan Modra, Jeff Law

Tested on hppa-linux.  No regressions were observed.

Dave

On 2023-12-15 7:19 a.m., Jan Beulich wrote:
> For some ELF targets .text/.data are overridden. In that case
> obj_elf_{text,data}() need calling, just like .code vectors to that
> function for the remaining ELF targets.
>
> While there also hand on the function arguments, even if right now
> they're meaningless. This matches what other targets' code does.
>
> --- a/gas/config/tc-hppa.c
> +++ b/gas/config/tc-hppa.c
> @@ -6199,7 +6199,7 @@ pa_callinfo (int unused ATTRIBUTE_UNUSED
>      label when finished.  */
>   
>   static void
> -pa_text (int unused ATTRIBUTE_UNUSED)
> +pa_text (int arg)
>   {
>   #ifdef OBJ_SOM
>     current_space = is_defined_space ("$TEXT$");
> @@ -6207,21 +6207,32 @@ pa_text (int unused ATTRIBUTE_UNUSED)
>       = pa_subsegment_to_subspace (current_space->sd_seg, 0);
>   #endif
>   
> -  s_text (0);
> +#ifdef OBJ_ELF
> +  obj_elf_text (arg);
> +#else
> +  s_text (arg);
> +#endif
> +
>     pa_undefine_label ();
>   }
>   
>   /* Switch to the data space.  As usual delete our label.  */
>   
>   static void
> -pa_data (int unused ATTRIBUTE_UNUSED)
> +pa_data (int arg)
>   {
>   #ifdef OBJ_SOM
>     current_space = is_defined_space ("$PRIVATE$");
>     current_subspace
>       = pa_subsegment_to_subspace (current_space->sd_seg, 0);
>   #endif
> -  s_data (0);
> +
> +#ifdef OBJ_ELF
> +  obj_elf_data (arg);
> +#else
> +  s_data (arg);
> +#endif
> +
>     pa_undefine_label ();
>   }
>   
>


-- 
John David Anglin  dave.anglin@bell.net


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 20/22] nios2: fix .text/.data interaction with .previous
  2023-12-15 12:19 ` [PATCH 20/22] nios2: " Jan Beulich
@ 2023-12-15 19:00   ` Sandra Loosemore
  0 siblings, 0 replies; 27+ messages in thread
From: Sandra Loosemore @ 2023-12-15 19:00 UTC (permalink / raw)
  To: Jan Beulich, Binutils
  Cc: Nick Clifton, Alan Modra, Sandra Loosemore, Andrew Jenner

On 12/15/23 05:19, Jan Beulich wrote:
> Just like obj_elf_section() is called for .section, obj_elf_{text,data}()
> need calling for .text/.data.

Looks fine to me.

-Sandra

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 03/22] RISC-V: drop .bss override
  2023-12-15 12:07 ` [PATCH 03/22] RISC-V: " Jan Beulich
@ 2023-12-21  6:44   ` Nelson Chu
  0 siblings, 0 replies; 27+ messages in thread
From: Nelson Chu @ 2023-12-21  6:44 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Binutils, Nick Clifton, Alan Modra, Palmer Dabbelt,
	Andrew Waterman, Jim Wilson

[-- Attachment #1: Type: text/plain, Size: 1519 bytes --]

I passed the regressions of riscv-gnu-toolchain, so if no one objects, then
it seems safe to commit.

Thanks
Nelson


On Fri, Dec 15, 2023 at 8:07 PM Jan Beulich <jbeulich@suse.com> wrote:

> It doesn't look to be a good idea to override the custom handler that
> ELF has; afaict doing so broke .previous, and a sub-section specifier
> wasn't accepted either.
>
> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -4471,15 +4471,6 @@ s_dtprel (int bytes)
>    demand_empty_rest_of_line ();
>  }
>
> -/* Handle the .bss pseudo-op.  */
> -
> -static void
> -s_bss (int ignore ATTRIBUTE_UNUSED)
> -{
> -  subseg_set (bss_section, 0);
> -  demand_empty_rest_of_line ();
> -}
> -
>  static void
>  riscv_make_nops (char *buf, bfd_vma bytes)
>  {
> @@ -5202,7 +5193,6 @@ static const pseudo_typeS riscv_pseudo_t
>    {"dword", cons, 8},
>    {"dtprelword", s_dtprel, 4},
>    {"dtpreldword", s_dtprel, 8},
> -  {"bss", s_bss, 0},
>    {"uleb128", s_riscv_leb128, 0},
>    {"sleb128", s_riscv_leb128, 1},
>    {"insn", s_riscv_insn, 0},
> --- a/gas/doc/c-riscv.texi
> +++ b/gas/doc/c-riscv.texi
> @@ -138,10 +138,6 @@ Emits a DTP-relative word (or double-wor
>  meant to be used by the compiler in shared libraries for DWARF debug info
> for
>  thread local variables.
>
> -@cindex BSS directive
> -@item .bss
> -Sets the current section to the BSS section.
> -
>  @cindex LEB128 directives
>  @item .uleb128 @var{value}
>  @itemx .sleb128 @var{value}
>
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 00/22] ELF: correct handling of simplified section directives
  2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
                   ` (21 preceding siblings ...)
  2023-12-15 12:20 ` [PATCH 22/22] ELF: test certain .text/.data usages Jan Beulich
@ 2024-01-02  0:40 ` Alan Modra
  22 siblings, 0 replies; 27+ messages in thread
From: Alan Modra @ 2024-01-02  0:40 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Binutils, Nick Clifton

On Fri, Dec 15, 2023 at 12:59:39PM +0100, Jan Beulich wrote:
> Various targets override .bss (many), .text, or .data (a few) handling,
> and sadly more often than not these overrides break things: In some
> cases .previous doesn't work as intended, while in other cases the
> sub-section specifier that ELF allows also for .bss for isn't recognized.
> Fix this (first primarily for .bss, then for .text/.data), putting in
> place tests to cover these pretty universal ELF aspects.

Looks good to me.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2024-01-02  0:40 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-15 11:59 [PATCH 00/22] ELF: correct handling of simplified section directives Jan Beulich
2023-12-15 12:06 ` [PATCH 01/22] Arm: drop .bss override Jan Beulich
2023-12-15 12:06 ` [PATCH 02/22] Arm64: " Jan Beulich
2023-12-15 12:07 ` [PATCH 03/22] RISC-V: " Jan Beulich
2023-12-21  6:44   ` Nelson Chu
2023-12-15 12:08 ` [PATCH 04/22] IA64: " Jan Beulich
2023-12-15 12:09 ` [PATCH 05/22] bfin: " Jan Beulich
2023-12-15 12:10 ` [PATCH 06/22] m32c: " Jan Beulich
2023-12-15 12:10 ` [PATCH 07/22] m68k: " Jan Beulich
2023-12-15 12:11 ` [PATCH 08/22] microblaze: drop/restrict override of .text, .data, and .bss Jan Beulich
2023-12-15 12:12 ` [PATCH 09/22] rl78: drop .bss override Jan Beulich
2023-12-15 12:12 ` [PATCH 10/22] rx: " Jan Beulich
2023-12-15 12:13 ` [PATCH 11/22] s390: " Jan Beulich
2023-12-15 12:14 ` [PATCH 12/22] score: " Jan Beulich
2023-12-15 12:15 ` [PATCH 13/22] visium: drop .bss and .skip overrides Jan Beulich
2023-12-15 12:16 ` [PATCH 14/22] z80: drop .bss override Jan Beulich
2023-12-15 12:16 ` [PATCH 15/22] ELF: test certain .bss usages Jan Beulich
2023-12-15 12:16 ` [PATCH 16/22] gas: correct .bss documentation for non-ELF Jan Beulich
2023-12-15 12:17 ` [PATCH 17/22] v850: drop .bss override Jan Beulich
2023-12-15 12:18 ` [PATCH 18/22] d30v: fix .text/.data interaction with .previous Jan Beulich
2023-12-15 12:19 ` [PATCH 19/22] hppa/ELF: " Jan Beulich
2023-12-15 16:37   ` John David Anglin
2023-12-15 12:19 ` [PATCH 20/22] nios2: " Jan Beulich
2023-12-15 19:00   ` Sandra Loosemore
2023-12-15 12:20 ` [PATCH 21/22] pru: " Jan Beulich
2023-12-15 12:20 ` [PATCH 22/22] ELF: test certain .text/.data usages Jan Beulich
2024-01-02  0:40 ` [PATCH 00/22] ELF: correct handling of simplified section directives Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).