public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Patch mach-o  3/3] section directives needed to support GCC
@ 2011-12-13  2:23 Iain Sandoe
  2011-12-13  9:50 ` Tristan Gingold
  0 siblings, 1 reply; 9+ messages in thread
From: Iain Sandoe @ 2011-12-13  2:23 UTC (permalink / raw)
  To: binutils; +Cc: Tristan Gingold


mach-o defaults to starting up with only the text section defined -
the data and bss sections are created on demand and not emitted  
otherwise.

further, it is possible to suppress even the text section, such that  
an object file can contain only specialized sections
(TODO to implement the c/l switch to do this).

this applies on top of part 1.

cheers
Iain

gas:

	* as.c (perform_an_assembly_pass): Do not create text, data and bass  
sections
	for MACH-O.  Do not switch to the text section.
	* config/obj-macho.c (obj_mach_o_segT_from_bfd_name): Forward decl.
	(mach_o_begin): Startup with only text section unless suppressed.
	* config/obj-macho.h (obj_begin): define to mach_o_begin ().

gas/testsuite:

	* gas/mach-o/empty.s: New.
	* gas/mach-o/sections-1.d: Amend to recognize that bss is not emitted  
by default.
	* gas/mach-o/sections-2.d: New.

  gas/as.c                              |    6 ++++++
  gas/config/obj-macho.c                |   27 ++++++++++++++++++++++++ 
+++
  gas/config/obj-macho.h                |    4 ++++
  gas/testsuite/gas/mach-o/empty.s      |    2 ++
  gas/testsuite/gas/mach-o/sections-1.d |    5 -----
  gas/testsuite/gas/mach-o/sections-2.d |   14 ++++++++++++++
  6 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/gas/as.c b/gas/as.c
index b99ea1e..1325038 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -1037,10 +1037,13 @@ static void
  perform_an_assembly_pass (int argc, char ** argv)
  {
    int saw_a_file = 0;
+#ifndef OBJ_MACH_O
    flagword applicable;
+#endif

    need_pass_2 = 0;

+#ifndef OBJ_MACH_O
    /* Create the standard sections, and those the assembler uses
       internally.  */
    text_section = subseg_new (TEXT_SECTION_NAME, 0);
@@ -1057,12 +1060,15 @@ perform_an_assembly_pass (int argc, char **  
argv)
  				       | SEC_DATA));
    bfd_set_section_flags (stdoutput, bss_section, applicable &  
SEC_ALLOC);
    seg_info (bss_section)->bss = 1;
+#endif
    subseg_new (BFD_ABS_SECTION_NAME, 0);
    subseg_new (BFD_UND_SECTION_NAME, 0);
    reg_section = subseg_new ("*GAS `reg' section*", 0);
    expr_section = subseg_new ("*GAS `expr' section*", 0);

+#ifndef OBJ_MACH_O
    subseg_set (text_section, 0);
+#endif

    /* This may add symbol table entries, which requires having an  
open BFD,
       and sections already created.  */
diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c
index 1aa24f7..5b32803 100644
--- a/gas/config/obj-macho.c
+++ b/gas/config/obj-macho.c
@@ -45,12 +45,39 @@
  #include "mach-o/loader.h"
  #include "obj-macho.h"

+/* Forward decl.  */
+static segT obj_mach_o_segT_from_bfd_name (const char *nam, int  
must_succeed);
+
  /* TODO: Implement "-dynamic"/"-static" command line options.  */
  int is_static;

+/* TODO: Implement the "-n" command line option to suppress the initial
+   switch to the text segment.  */
+int start_with_text_section = 1;
+
  /* Allow for special re-ordering on output.  */
  int seen_objc_section;

+/* Start-up: At present, just create the sections we want.  */
+void
+mach_o_begin (void)
+{
+  /* Mach-O only defines the .text section by default, and even this  
can
+     be suppressed by a flag.  In the latter event, the first code MUST
+     be a section definition.  */
+  if (start_with_text_section)
+    {
+      text_section = obj_mach_o_segT_from_bfd_name  
(TEXT_SECTION_NAME, 1);
+      subseg_set (text_section, 0);
+      if (is_static)
+	{
+	  bfd_mach_o_section *mo_sec
+		= OBJ_MACH_O_GET_BACKEND_SECT_DATA (stdoutput, text_section);
+	  mo_sec->flags &= ~BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS;
+	}
+    }
+}
+
  static void
  obj_mach_o_weak (int ignore ATTRIBUTE_UNUSED)
  {
diff --git a/gas/config/obj-macho.h b/gas/config/obj-macho.h
index 1203cd8..0b62df2 100644
--- a/gas/config/obj-macho.h
+++ b/gas/config/obj-macho.h
@@ -30,6 +30,10 @@

  #define OUTPUT_FLAVOR bfd_target_mach_o_flavour

+/* We want to control how the sections are pre-defined on startup.  */
+#define obj_begin() mach_o_begin ()
+extern void mach_o_begin (void);
+
  /* All our align expressions are power of two.  */
  #define USE_ALIGN_PTWO

diff --git a/gas/testsuite/gas/mach-o/empty.s b/gas/testsuite/gas/mach- 
o/empty.s
new file mode 100644
index 0000000..b2b70f4
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/empty.s
@@ -0,0 +1,2 @@
+# nothing here
+
diff --git a/gas/testsuite/gas/mach-o/sections-1.d b/gas/testsuite/gas/ 
mach-o/sections-1.d
index 25ddc25..85d9850 100644
--- a/gas/testsuite/gas/mach-o/sections-1.d
+++ b/gas/testsuite/gas/mach-o/sections-1.d
@@ -11,11 +11,6 @@
    align: 0  nreloc: 0  reloff: (00000000)?00000000
    flags: 00000000 \(type: regular attr: -\)
    reserved1: 0x0  reserved2: 0x0  reserved3: 0x0
- Section: __bss            __DATA           \(bfdname: .bss\)
-  addr: (00000000)?00000000 size: (00000000)?00000000 offset:  
(00000000)?00000000
-  align: 0  nreloc: 0  reloff: (00000000)?00000000
-  flags: 00000001 \(type: zerofill attr: -\)
-  reserved1: 0x0  reserved2: 0x0  reserved3: 0x0
   Section: __textcoal_nt    __TEXT           \(bfdname:  
__TEXT.__textcoal_nt\)
    addr: (00000000)?00000000 size: (00000000)?00000000 offset:  
(00000000)?00000000
    align: 0  nreloc: 0  reloff: (00000000)?00000000
diff --git a/gas/testsuite/gas/mach-o/sections-2.d b/gas/testsuite/gas/ 
mach-o/sections-2.d
new file mode 100644
index 0000000..9d24f9a
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/sections-2.d
@@ -0,0 +1,14 @@
+#objdump: -h
+#source: empty.s
+# we should only see a text section by default.
+.*: +file format mach-o.*
+#...
+Idx Name.*
+  0 .text.*
+.*
+#failif
+  1 .data.*
+.*
+  2 .bss.*
+.*
+

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

* Re: [Patch mach-o  3/3] section directives needed to support GCC
  2011-12-13  2:23 [Patch mach-o 3/3] section directives needed to support GCC Iain Sandoe
@ 2011-12-13  9:50 ` Tristan Gingold
  2011-12-13 10:01   ` Iain Sandoe
  2011-12-13 10:29   ` Alan Modra
  0 siblings, 2 replies; 9+ messages in thread
From: Tristan Gingold @ 2011-12-13  9:50 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: binutils


On Dec 13, 2011, at 3:23 AM, Iain Sandoe wrote:

> 
> mach-o defaults to starting up with only the text section defined -
> the data and bss sections are created on demand and not emitted otherwise.
> 
> further, it is possible to suppress even the text section, such that an object file can contain only specialized sections
> (TODO to implement the c/l switch to do this).

As this touches common code, I can't approve it.

An alternative is to remove these sections unless they are not empty (ok, slightly different semantic).  Here is what I wrote to achieve that:

+++ b/gas/config/obj-macho.c
@@ -431,5 +431,21 @@ obj_mach_o_set_subsections (bfd *abfd ATTRIBUTE_UNUSED,
 void
 obj_mach_o_frob_file_before_adjust (void)
 {
+#if 1
+  /* Do not write the data and bss section if they are empty.  This matches
+     original assembler behaviour.  */
+  /* FIXME: do this like reg_section ?  */
+  if (bfd_section_size (stdoutput, data_section) == 0)
+    {
+      bfd_section_list_remove (stdoutput, data_section);
+      stdoutput->section_count--;
+    }
+  if (bfd_section_size (stdoutput, bss_section) == 0)
+    {
+      bfd_section_list_remove (stdoutput, bss_section);
+      stdoutput->section_count--;
+    }
+#endif
+
   bfd_map_over_sections (stdoutput, obj_mach_o_set_subsections, (char *) 0);
 }

Tristan.

> 
> this applies on top of part 1.
> 
> cheers
> Iain
> 
> gas:
> 
> 	* as.c (perform_an_assembly_pass): Do not create text, data and bass sections
> 	for MACH-O.  Do not switch to the text section.
> 	* config/obj-macho.c (obj_mach_o_segT_from_bfd_name): Forward decl.
> 	(mach_o_begin): Startup with only text section unless suppressed.
> 	* config/obj-macho.h (obj_begin): define to mach_o_begin ().
> 
> gas/testsuite:
> 
> 	* gas/mach-o/empty.s: New.
> 	* gas/mach-o/sections-1.d: Amend to recognize that bss is not emitted by default.
> 	* gas/mach-o/sections-2.d: New.
> 
> gas/as.c                              |    6 ++++++
> gas/config/obj-macho.c                |   27 +++++++++++++++++++++++++++
> gas/config/obj-macho.h                |    4 ++++
> gas/testsuite/gas/mach-o/empty.s      |    2 ++
> gas/testsuite/gas/mach-o/sections-1.d |    5 -----
> gas/testsuite/gas/mach-o/sections-2.d |   14 ++++++++++++++
> 6 files changed, 53 insertions(+), 5 deletions(-)
> 
> diff --git a/gas/as.c b/gas/as.c
> index b99ea1e..1325038 100644
> --- a/gas/as.c
> +++ b/gas/as.c
> @@ -1037,10 +1037,13 @@ static void
> perform_an_assembly_pass (int argc, char ** argv)
> {
>   int saw_a_file = 0;
> +#ifndef OBJ_MACH_O
>   flagword applicable;
> +#endif
> 
>   need_pass_2 = 0;
> 
> +#ifndef OBJ_MACH_O
>   /* Create the standard sections, and those the assembler uses
>      internally.  */
>   text_section = subseg_new (TEXT_SECTION_NAME, 0);
> @@ -1057,12 +1060,15 @@ perform_an_assembly_pass (int argc, char ** argv)
> 				       | SEC_DATA));
>   bfd_set_section_flags (stdoutput, bss_section, applicable & SEC_ALLOC);
>   seg_info (bss_section)->bss = 1;
> +#endif
>   subseg_new (BFD_ABS_SECTION_NAME, 0);
>   subseg_new (BFD_UND_SECTION_NAME, 0);
>   reg_section = subseg_new ("*GAS `reg' section*", 0);
>   expr_section = subseg_new ("*GAS `expr' section*", 0);
> 
> +#ifndef OBJ_MACH_O
>   subseg_set (text_section, 0);
> +#endif
> 
>   /* This may add symbol table entries, which requires having an open BFD,
>      and sections already created.  */
> diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c
> index 1aa24f7..5b32803 100644
> --- a/gas/config/obj-macho.c
> +++ b/gas/config/obj-macho.c
> @@ -45,12 +45,39 @@
> #include "mach-o/loader.h"
> #include "obj-macho.h"
> 
> +/* Forward decl.  */
> +static segT obj_mach_o_segT_from_bfd_name (const char *nam, int must_succeed);
> +
> /* TODO: Implement "-dynamic"/"-static" command line options.  */
> int is_static;
> 
> +/* TODO: Implement the "-n" command line option to suppress the initial
> +   switch to the text segment.  */
> +int start_with_text_section = 1;
> +
> /* Allow for special re-ordering on output.  */
> int seen_objc_section;
> 
> +/* Start-up: At present, just create the sections we want.  */
> +void
> +mach_o_begin (void)
> +{
> +  /* Mach-O only defines the .text section by default, and even this can
> +     be suppressed by a flag.  In the latter event, the first code MUST
> +     be a section definition.  */
> +  if (start_with_text_section)
> +    {
> +      text_section = obj_mach_o_segT_from_bfd_name (TEXT_SECTION_NAME, 1);
> +      subseg_set (text_section, 0);
> +      if (is_static)
> +	{
> +	  bfd_mach_o_section *mo_sec
> +		= OBJ_MACH_O_GET_BACKEND_SECT_DATA (stdoutput, text_section);
> +	  mo_sec->flags &= ~BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS;
> +	}
> +    }
> +}
> +
> static void
> obj_mach_o_weak (int ignore ATTRIBUTE_UNUSED)
> {
> diff --git a/gas/config/obj-macho.h b/gas/config/obj-macho.h
> index 1203cd8..0b62df2 100644
> --- a/gas/config/obj-macho.h
> +++ b/gas/config/obj-macho.h
> @@ -30,6 +30,10 @@
> 
> #define OUTPUT_FLAVOR bfd_target_mach_o_flavour
> 
> +/* We want to control how the sections are pre-defined on startup.  */
> +#define obj_begin() mach_o_begin ()
> +extern void mach_o_begin (void);
> +
> /* All our align expressions are power of two.  */
> #define USE_ALIGN_PTWO
> 
> diff --git a/gas/testsuite/gas/mach-o/empty.s b/gas/testsuite/gas/mach-o/empty.s
> new file mode 100644
> index 0000000..b2b70f4
> --- /dev/null
> +++ b/gas/testsuite/gas/mach-o/empty.s
> @@ -0,0 +1,2 @@
> +# nothing here
> +
> diff --git a/gas/testsuite/gas/mach-o/sections-1.d b/gas/testsuite/gas/mach-o/sections-1.d
> index 25ddc25..85d9850 100644
> --- a/gas/testsuite/gas/mach-o/sections-1.d
> +++ b/gas/testsuite/gas/mach-o/sections-1.d
> @@ -11,11 +11,6 @@
>   align: 0  nreloc: 0  reloff: (00000000)?00000000
>   flags: 00000000 \(type: regular attr: -\)
>   reserved1: 0x0  reserved2: 0x0  reserved3: 0x0
> - Section: __bss            __DATA           \(bfdname: .bss\)
> -  addr: (00000000)?00000000 size: (00000000)?00000000 offset: (00000000)?00000000
> -  align: 0  nreloc: 0  reloff: (00000000)?00000000
> -  flags: 00000001 \(type: zerofill attr: -\)
> -  reserved1: 0x0  reserved2: 0x0  reserved3: 0x0
>  Section: __textcoal_nt    __TEXT           \(bfdname: __TEXT.__textcoal_nt\)
>   addr: (00000000)?00000000 size: (00000000)?00000000 offset: (00000000)?00000000
>   align: 0  nreloc: 0  reloff: (00000000)?00000000
> diff --git a/gas/testsuite/gas/mach-o/sections-2.d b/gas/testsuite/gas/mach-o/sections-2.d
> new file mode 100644
> index 0000000..9d24f9a
> --- /dev/null
> +++ b/gas/testsuite/gas/mach-o/sections-2.d
> @@ -0,0 +1,14 @@
> +#objdump: -h
> +#source: empty.s
> +# we should only see a text section by default.
> +.*: +file format mach-o.*
> +#...
> +Idx Name.*
> +  0 .text.*
> +.*
> +#failif
> +  1 .data.*
> +.*
> +  2 .bss.*
> +.*
> +
> 

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

* Re: [Patch mach-o  3/3] section directives needed to support GCC
  2011-12-13  9:50 ` Tristan Gingold
@ 2011-12-13 10:01   ` Iain Sandoe
  2011-12-13 10:38     ` Tristan Gingold
  2011-12-13 10:29   ` Alan Modra
  1 sibling, 1 reply; 9+ messages in thread
From: Iain Sandoe @ 2011-12-13 10:01 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils

Hi Tristan,

Thanks for reviewing the three patches - apologies that the first one  
was so  large.
... I would normally try to make smaller bites - but I guess I felt  
that it did all belong together (a lot of the bulk is in repetitive  
table stuff).

Do you wish me to repost after rebasing and addressing your points -  
(or I could send to you as a diff, if you intend to apply it).

On 13 Dec 2011, at 09:50, Tristan Gingold wrote:e

>
> On Dec 13, 2011, at 3:23 AM, Iain Sandoe wrote:
>
>>
>> mach-o defaults to starting up with only the text section defined -
>> the data and bss sections are created on demand and not emitted  
>> otherwise.
>>
>> further, it is possible to suppress even the text section, such  
>> that an object file can contain only specialized sections
>> (TODO to implement the c/l switch to do this).
>
> As this touches common code, I can't approve it.
>
> An alternative is to remove these sections unless they are not empty  
> (ok, slightly different semantic).  Here is what I wrote to achieve  
> that:

I didn't do that because ISTM that we can't tell the difference  
between gas inserting them by default - and the User intentionally  
defining them as empty (for some devious reason).

I suppose we could keep track of whether the User does define them....

WDYT?
Iain

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

* Re: [Patch mach-o  3/3] section directives needed to support GCC
  2011-12-13  9:50 ` Tristan Gingold
  2011-12-13 10:01   ` Iain Sandoe
@ 2011-12-13 10:29   ` Alan Modra
  1 sibling, 0 replies; 9+ messages in thread
From: Alan Modra @ 2011-12-13 10:29 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: Iain Sandoe, binutils

On Tue, Dec 13, 2011 at 10:50:26AM +0100, Tristan Gingold wrote:
> 
> On Dec 13, 2011, at 3:23 AM, Iain Sandoe wrote:
> 
> > 
> > mach-o defaults to starting up with only the text section defined -
> > the data and bss sections are created on demand and not emitted otherwise.
> > 
> > further, it is possible to suppress even the text section, such that an object file can contain only specialized sections
> > (TODO to implement the c/l switch to do this).
> 
> As this touches common code, I can't approve it.

I'll OK the as.c changes if you're happy with the rest.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [Patch mach-o  3/3] section directives needed to support GCC
  2011-12-13 10:01   ` Iain Sandoe
@ 2011-12-13 10:38     ` Tristan Gingold
  2011-12-13 14:09       ` Rebased : " Iain Sandoe
  0 siblings, 1 reply; 9+ messages in thread
From: Tristan Gingold @ 2011-12-13 10:38 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: binutils


On Dec 13, 2011, at 11:01 AM, Iain Sandoe wrote:

> Hi Tristan,
> 
> Thanks for reviewing the three patches - apologies that the first one was so  large.
> ... I would normally try to make smaller bites - but I guess I felt that it did all belong together (a lot of the bulk is in repetitive table stuff).
> 
> Do you wish me to repost after rebasing and addressing your points - (or I could send to you as a diff, if you intend to apply it).

Yes, please resubmit.  I can take the diff from the mailing list.

> On 13 Dec 2011, at 09:50, Tristan Gingold wrote:e
> 
>> 
>> On Dec 13, 2011, at 3:23 AM, Iain Sandoe wrote:
>> 
>>> 
>>> mach-o defaults to starting up with only the text section defined -
>>> the data and bss sections are created on demand and not emitted otherwise.
>>> 
>>> further, it is possible to suppress even the text section, such that an object file can contain only specialized sections
>>> (TODO to implement the c/l switch to do this).
>> 
>> As this touches common code, I can't approve it.
>> 
>> An alternative is to remove these sections unless they are not empty (ok, slightly different semantic).  Here is what I wrote to achieve that:
> 
> I didn't do that because ISTM that we can't tell the difference between gas inserting them by default - and the User intentionally defining them as empty (for some devious reason).
> 
> I suppose we could keep track of whether the User does define them....
> 
> WDYT?

I think this matter (not emitting .data and .bss) is really a detail.  AFAIK, ld is happy if the sections are empty.

Anyway, as Alan has approved your changes, I am ok with them.

Tristan.

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

* Rebased : [Patch mach-o  3/3] section directives needed to support GCC
  2011-12-13 10:38     ` Tristan Gingold
@ 2011-12-13 14:09       ` Iain Sandoe
  2011-12-14 15:38         ` Tristan Gingold
  0 siblings, 1 reply; 9+ messages in thread
From: Iain Sandoe @ 2011-12-13 14:09 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils

minor tweaks here to deal with the changes to part 2.

On 13 Dec 2011, at 10:38, Tristan Gingold wrote:
> I think this matter (not emitting .data and .bss) is really a detail.

Yes, it is .. and I'm happy to leave until it shows as a bug
..  or just to apply and be the same as the system tools.

>   AFAIK, ld is happy if the sections are empty.

OK. I wasn't sure - don't have complete coverage of ld variants here.

> Anyway, as Alan has approved your changes, I am ok with them.

... here is the rebased patch anyway ...
cheers
Iain

---


  gas/as.c                              |    6 ++++++
  gas/config/obj-macho.c                |   27 ++++++++++++++++++++++++ 
+++
  gas/config/obj-macho.h                |    4 ++++
  gas/testsuite/gas/mach-o/sections-1.d |    5 -----
  gas/testsuite/gas/mach-o/sections-2.d |   14 ++++++++++++++
  5 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/gas/as.c b/gas/as.c
index b99ea1e..1325038 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -1037,10 +1037,13 @@ static void
  perform_an_assembly_pass (int argc, char ** argv)
  {
    int saw_a_file = 0;
+#ifndef OBJ_MACH_O
    flagword applicable;
+#endif

    need_pass_2 = 0;

+#ifndef OBJ_MACH_O
    /* Create the standard sections, and those the assembler uses
       internally.  */
    text_section = subseg_new (TEXT_SECTION_NAME, 0);
@@ -1057,12 +1060,15 @@ perform_an_assembly_pass (int argc, char **  
argv)
  				       | SEC_DATA));
    bfd_set_section_flags (stdoutput, bss_section, applicable &  
SEC_ALLOC);
    seg_info (bss_section)->bss = 1;
+#endif
    subseg_new (BFD_ABS_SECTION_NAME, 0);
    subseg_new (BFD_UND_SECTION_NAME, 0);
    reg_section = subseg_new ("*GAS `reg' section*", 0);
    expr_section = subseg_new ("*GAS `expr' section*", 0);

+#ifndef OBJ_MACH_O
    subseg_set (text_section, 0);
+#endif

    /* This may add symbol table entries, which requires having an  
open BFD,
       and sections already created.  */
diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c
index 018f653..4e55ee4 100644
--- a/gas/config/obj-macho.c
+++ b/gas/config/obj-macho.c
@@ -45,14 +45,41 @@
  #include "mach-o/loader.h"
  #include "obj-macho.h"

+/* Forward decl.  */
+static segT obj_mach_o_segT_from_bfd_name (const char *nam, int  
must_succeed);
+
  /* TODO: Implement "-dynamic"/"-static" command line options.  */

  static int obj_mach_o_is_static;

+/* TODO: Implement the "-n" command line option to suppress the initial
+   switch to the text segment.  */
+int start_with_text_section = 1;
+
  /* Allow for special re-ordering on output.  */

  static int seen_objc_section;

+/* Start-up: At present, just create the sections we want.  */
+void
+mach_o_begin (void)
+{
+  /* Mach-O only defines the .text section by default, and even this  
can
+     be suppressed by a flag.  In the latter event, the first code MUST
+     be a section definition.  */
+  if (start_with_text_section)
+    {
+      text_section = obj_mach_o_segT_from_bfd_name  
(TEXT_SECTION_NAME, 1);
+      subseg_set (text_section, 0);
+      if (obj_mach_o_is_static)
+	{
+	  bfd_mach_o_section *mo_sec
+			= bfd_mach_o_get_mach_o_section (text_section);
+	  mo_sec->flags &= ~BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS;
+	}
+    }
+}
+
  static void
  obj_mach_o_weak (int ignore ATTRIBUTE_UNUSED)
  {
diff --git a/gas/config/obj-macho.h b/gas/config/obj-macho.h
index 94c1cde..d9b0b33 100644
--- a/gas/config/obj-macho.h
+++ b/gas/config/obj-macho.h
@@ -30,6 +30,10 @@

  #define OUTPUT_FLAVOR bfd_target_mach_o_flavour

+/* We want to control how the sections are pre-defined on startup.  */
+#define obj_begin() mach_o_begin ()
+extern void mach_o_begin (void);
+
  /* All our align expressions are power of two.  */
  #define USE_ALIGN_PTWO

diff --git a/gas/testsuite/gas/mach-o/sections-1.d b/gas/testsuite/gas/ 
mach-o/sections-1.d
index a70af9b..5b8a8fa 100644
--- a/gas/testsuite/gas/mach-o/sections-1.d
+++ b/gas/testsuite/gas/mach-o/sections-1.d
@@ -11,11 +11,6 @@
    align: 0  nreloc: 0  reloff: (00000000)?00000000
    flags: 00000000 \(type: regular attr: -\)
    reserved1: 0x0  reserved2: 0x0  reserved3: 0x0
- Section: __bss            __DATA           \(bfdname: .bss\)
-  addr: (00000000)?00000000 size: (00000000)?00000000 offset:  
(00000000)?00000000
-  align: 0  nreloc: 0  reloff: (00000000)?00000000
-  flags: 00000001 \(type: zerofill attr: -\)
-  reserved1: 0x0  reserved2: 0x0  reserved3: 0x0
   Section: __textcoal_nt    __TEXT           \(bfdname:  
__TEXT.__textcoal_nt\)
    addr: (00000000)?00000000 size: (00000000)?00000000 offset:  
(00000000)?00000000
    align: 0  nreloc: 0  reloff: (00000000)?00000000
diff --git a/gas/testsuite/gas/mach-o/sections-2.d b/gas/testsuite/gas/ 
mach-o/sections-2.d
new file mode 100644
index 0000000..9d24f9a
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/sections-2.d
@@ -0,0 +1,14 @@
+#objdump: -h
+#source: empty.s
+# we should only see a text section by default.
+.*: +file format mach-o.*
+#...
+Idx Name.*
+  0 .text.*
+.*
+#failif
+  1 .data.*
+.*
+  2 .bss.*
+.*
+

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

* Re: Rebased : [Patch mach-o  3/3] section directives needed to support GCC
  2011-12-13 14:09       ` Rebased : " Iain Sandoe
@ 2011-12-14 15:38         ` Tristan Gingold
  2011-12-14 16:06           ` Iain Sandoe
  0 siblings, 1 reply; 9+ messages in thread
From: Tristan Gingold @ 2011-12-14 15:38 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: binutils


On Dec 13, 2011, at 3:08 PM, Iain Sandoe wrote:

> minor tweaks here to deal with the changes to part 2.
> 
> On 13 Dec 2011, at 10:38, Tristan Gingold wrote:
>> I think this matter (not emitting .data and .bss) is really a detail.
> 
> Yes, it is .. and I'm happy to leave until it shows as a bug
> ..  or just to apply and be the same as the system tools.
> 
>>  AFAIK, ld is happy if the sections are empty.
> 
> OK. I wasn't sure - don't have complete coverage of ld variants here.
> 
>> Anyway, as Alan has approved your changes, I am ok with them.
> 
> ... here is the rebased patch anyway …

Last minute minor issue: local variable in obj-macho.c.  See below.

> cheers
> Iain
> 
> ---
> 
> 
> gas/as.c                              |    6 ++++++
> gas/config/obj-macho.c                |   27 +++++++++++++++++++++++++++
> gas/config/obj-macho.h                |    4 ++++
> gas/testsuite/gas/mach-o/sections-1.d |    5 -----
> gas/testsuite/gas/mach-o/sections-2.d |   14 ++++++++++++++
> 5 files changed, 51 insertions(+), 5 deletions(-)
> 
> diff --git a/gas/as.c b/gas/as.c
> index b99ea1e..1325038 100644
> --- a/gas/as.c
> +++ b/gas/as.c
> @@ -1037,10 +1037,13 @@ static void
> perform_an_assembly_pass (int argc, char ** argv)
> {
>   int saw_a_file = 0;
> +#ifndef OBJ_MACH_O
>   flagword applicable;
> +#endif
> 
>   need_pass_2 = 0;
> 
> +#ifndef OBJ_MACH_O
>   /* Create the standard sections, and those the assembler uses
>      internally.  */
>   text_section = subseg_new (TEXT_SECTION_NAME, 0);
> @@ -1057,12 +1060,15 @@ perform_an_assembly_pass (int argc, char ** argv)
> 				       | SEC_DATA));
>   bfd_set_section_flags (stdoutput, bss_section, applicable & SEC_ALLOC);
>   seg_info (bss_section)->bss = 1;
> +#endif
>   subseg_new (BFD_ABS_SECTION_NAME, 0);
>   subseg_new (BFD_UND_SECTION_NAME, 0);
>   reg_section = subseg_new ("*GAS `reg' section*", 0);
>   expr_section = subseg_new ("*GAS `expr' section*", 0);
> 
> +#ifndef OBJ_MACH_O
>   subseg_set (text_section, 0);
> +#endif
> 
>   /* This may add symbol table entries, which requires having an open BFD,
>      and sections already created.  */
> diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c
> index 018f653..4e55ee4 100644
> --- a/gas/config/obj-macho.c
> +++ b/gas/config/obj-macho.c
> @@ -45,14 +45,41 @@
> #include "mach-o/loader.h"
> #include "obj-macho.h"
> 
> +/* Forward decl.  */
> +static segT obj_mach_o_segT_from_bfd_name (const char *nam, int must_succeed);
> +
> /* TODO: Implement "-dynamic"/"-static" command line options.  */
> 
> static int obj_mach_o_is_static;
> 
> +/* TODO: Implement the "-n" command line option to suppress the initial
> +   switch to the text segment.  */
> +int start_with_text_section = 1;

Static + obj_mach_o prefix would be nice!

Thanks,
Tristan.

> +
> /* Allow for special re-ordering on output.  */
> 
> static int seen_objc_section;
> 
> +/* Start-up: At present, just create the sections we want.  */
> +void
> +mach_o_begin (void)
> +{
> +  /* Mach-O only defines the .text section by default, and even this can
> +     be suppressed by a flag.  In the latter event, the first code MUST
> +     be a section definition.  */
> +  if (start_with_text_section)
> +    {
> +      text_section = obj_mach_o_segT_from_bfd_name (TEXT_SECTION_NAME, 1);
> +      subseg_set (text_section, 0);
> +      if (obj_mach_o_is_static)
> +	{
> +	  bfd_mach_o_section *mo_sec
> +			= bfd_mach_o_get_mach_o_section (text_section);
> +	  mo_sec->flags &= ~BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS;
> +	}
> +    }
> +}
> +
> static void
> obj_mach_o_weak (int ignore ATTRIBUTE_UNUSED)
> {
> diff --git a/gas/config/obj-macho.h b/gas/config/obj-macho.h
> index 94c1cde..d9b0b33 100644
> --- a/gas/config/obj-macho.h
> +++ b/gas/config/obj-macho.h
> @@ -30,6 +30,10 @@
> 
> #define OUTPUT_FLAVOR bfd_target_mach_o_flavour
> 
> +/* We want to control how the sections are pre-defined on startup.  */
> +#define obj_begin() mach_o_begin ()
> +extern void mach_o_begin (void);
> +
> /* All our align expressions are power of two.  */
> #define USE_ALIGN_PTWO
> 
> diff --git a/gas/testsuite/gas/mach-o/sections-1.d b/gas/testsuite/gas/mach-o/sections-1.d
> index a70af9b..5b8a8fa 100644
> --- a/gas/testsuite/gas/mach-o/sections-1.d
> +++ b/gas/testsuite/gas/mach-o/sections-1.d
> @@ -11,11 +11,6 @@
>   align: 0  nreloc: 0  reloff: (00000000)?00000000
>   flags: 00000000 \(type: regular attr: -\)
>   reserved1: 0x0  reserved2: 0x0  reserved3: 0x0
> - Section: __bss            __DATA           \(bfdname: .bss\)
> -  addr: (00000000)?00000000 size: (00000000)?00000000 offset: (00000000)?00000000
> -  align: 0  nreloc: 0  reloff: (00000000)?00000000
> -  flags: 00000001 \(type: zerofill attr: -\)
> -  reserved1: 0x0  reserved2: 0x0  reserved3: 0x0
>  Section: __textcoal_nt    __TEXT           \(bfdname: __TEXT.__textcoal_nt\)
>   addr: (00000000)?00000000 size: (00000000)?00000000 offset: (00000000)?00000000
>   align: 0  nreloc: 0  reloff: (00000000)?00000000
> diff --git a/gas/testsuite/gas/mach-o/sections-2.d b/gas/testsuite/gas/mach-o/sections-2.d
> new file mode 100644
> index 0000000..9d24f9a
> --- /dev/null
> +++ b/gas/testsuite/gas/mach-o/sections-2.d
> @@ -0,0 +1,14 @@
> +#objdump: -h
> +#source: empty.s
> +# we should only see a text section by default.
> +.*: +file format mach-o.*
> +#...
> +Idx Name.*
> +  0 .text.*
> +.*
> +#failif
> +  1 .data.*
> +.*
> +  2 .bss.*
> +.*
> +
> 

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

* Re: Rebased : [Patch mach-o  3/3] section directives needed to support GCC
  2011-12-14 15:38         ` Tristan Gingold
@ 2011-12-14 16:06           ` Iain Sandoe
  2011-12-29 10:58             ` Iain Sandoe
  0 siblings, 1 reply; 9+ messages in thread
From: Iain Sandoe @ 2011-12-14 16:06 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils

Hi Tristan,

Thanks very much for doing the extra work to make the commits!

On 14 Dec 2011, at 15:38, Tristan Gingold wrote:

>
> On Dec 13, 2011, at 3:08 PM, Iain Sandoe wrote:
>
>> minor tweaks here to deal with the changes to part 2.
>>
>> On 13 Dec 2011, at 10:38, Tristan Gingold wrote:
>>> I think this matter (not emitting .data and .bss) is really a  
>>> detail.
>>
>> Yes, it is .. and I'm happy to leave until it shows as a bug
>> ..  or just to apply and be the same as the system tools.
>>
>>> AFAIK, ld is happy if the sections are empty.
>>
>> OK. I wasn't sure - don't have complete coverage of ld variants here.
>>
>>> Anyway, as Alan has approved your changes, I am ok with them.
>>
>> ... here is the rebased patch anyway …
>
> Last minute minor issue: local variable in obj-macho.c.  See below.

I assume that the var might need to become global at the point that we  
implement parsing for the the c/l switch .. but it might as well be  
static for now.

done.. and also, as bonus, the seen_objc_ one before.

thanks again,
Iain


  gas/as.c                              |    6 +++++
  gas/config/obj-macho.c                |   34 ++++++++++++++++++++++++ 
++++++--
  gas/config/obj-macho.h                |    4 +++
  gas/testsuite/gas/mach-o/sections-1.d |    5 ----
  gas/testsuite/gas/mach-o/sections-2.d |   14 +++++++++++++
  5 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/gas/as.c b/gas/as.c
index b99ea1e..1325038 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -1037,10 +1037,13 @@ static void
  perform_an_assembly_pass (int argc, char ** argv)
  {
    int saw_a_file = 0;
+#ifndef OBJ_MACH_O
    flagword applicable;
+#endif

    need_pass_2 = 0;

+#ifndef OBJ_MACH_O
    /* Create the standard sections, and those the assembler uses
       internally.  */
    text_section = subseg_new (TEXT_SECTION_NAME, 0);
@@ -1057,12 +1060,15 @@ perform_an_assembly_pass (int argc, char **  
argv)
  				       | SEC_DATA));
    bfd_set_section_flags (stdoutput, bss_section, applicable &  
SEC_ALLOC);
    seg_info (bss_section)->bss = 1;
+#endif
    subseg_new (BFD_ABS_SECTION_NAME, 0);
    subseg_new (BFD_UND_SECTION_NAME, 0);
    reg_section = subseg_new ("*GAS `reg' section*", 0);
    expr_section = subseg_new ("*GAS `expr' section*", 0);

+#ifndef OBJ_MACH_O
    subseg_set (text_section, 0);
+#endif

    /* This may add symbol table entries, which requires having an  
open BFD,
       and sections already created.  */
diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c
index 018f653..fad3db6 100644
--- a/gas/config/obj-macho.c
+++ b/gas/config/obj-macho.c
@@ -45,13 +45,40 @@
  #include "mach-o/loader.h"
  #include "obj-macho.h"

+/* Forward decl.  */
+static segT obj_mach_o_segT_from_bfd_name (const char *nam, int  
must_succeed);
+
  /* TODO: Implement "-dynamic"/"-static" command line options.  */

  static int obj_mach_o_is_static;

+/* TODO: Implement the "-n" command line option to suppress the initial
+   switch to the text segment.  */
+static int obj_mach_o_start_with_text_section = 1;
+
  /* Allow for special re-ordering on output.  */

-static int seen_objc_section;
+static int obj_mach_o_seen_objc_section;
+
+/* Start-up: At present, just create the sections we want.  */
+void
+mach_o_begin (void)
+{
+  /* Mach-O only defines the .text section by default, and even this  
can
+     be suppressed by a flag.  In the latter event, the first code MUST
+     be a section definition.  */
+  if (obj_mach_o_start_with_text_section)
+    {
+      text_section = obj_mach_o_segT_from_bfd_name  
(TEXT_SECTION_NAME, 1);
+      subseg_set (text_section, 0);
+      if (obj_mach_o_is_static)
+	{
+	  bfd_mach_o_section *mo_sec
+			= bfd_mach_o_get_mach_o_section (text_section);
+	  mo_sec->flags &= ~BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS;
+	}
+    }
+}

  static void
  obj_mach_o_weak (int ignore ATTRIBUTE_UNUSED)
@@ -454,8 +481,9 @@ obj_mach_o_objc_section (int sect_index)
    section = obj_mach_o_segT_from_bfd_name  
(objc_sections[sect_index], 1);
    if (section != NULL)
      {
-      seen_objc_section = 1; /* We need to ensure that certain  
sections are
-				present and in the right order.  */
+      obj_mach_o_seen_objc_section = 1; /* We need to ensure that  
certain
+					   sections are present and in the
+					   right order.  */
        subseg_set (section, 0);
      }

diff --git a/gas/config/obj-macho.h b/gas/config/obj-macho.h
index 94c1cde..d9b0b33 100644
--- a/gas/config/obj-macho.h
+++ b/gas/config/obj-macho.h
@@ -30,6 +30,10 @@

  #define OUTPUT_FLAVOR bfd_target_mach_o_flavour

+/* We want to control how the sections are pre-defined on startup.  */
+#define obj_begin() mach_o_begin ()
+extern void mach_o_begin (void);
+
  /* All our align expressions are power of two.  */
  #define USE_ALIGN_PTWO

diff --git a/gas/testsuite/gas/mach-o/sections-1.d b/gas/testsuite/gas/ 
mach-o/sections-1.d
index a70af9b..5b8a8fa 100644
--- a/gas/testsuite/gas/mach-o/sections-1.d
+++ b/gas/testsuite/gas/mach-o/sections-1.d
@@ -11,11 +11,6 @@
    align: 0  nreloc: 0  reloff: (00000000)?00000000
    flags: 00000000 \(type: regular attr: -\)
    reserved1: 0x0  reserved2: 0x0  reserved3: 0x0
- Section: __bss            __DATA           \(bfdname: .bss\)
-  addr: (00000000)?00000000 size: (00000000)?00000000 offset:  
(00000000)?00000000
-  align: 0  nreloc: 0  reloff: (00000000)?00000000
-  flags: 00000001 \(type: zerofill attr: -\)
-  reserved1: 0x0  reserved2: 0x0  reserved3: 0x0
   Section: __textcoal_nt    __TEXT           \(bfdname:  
__TEXT.__textcoal_nt\)
    addr: (00000000)?00000000 size: (00000000)?00000000 offset:  
(00000000)?00000000
    align: 0  nreloc: 0  reloff: (00000000)?00000000
diff --git a/gas/testsuite/gas/mach-o/sections-2.d b/gas/testsuite/gas/ 
mach-o/sections-2.d
new file mode 100644
index 0000000..9d24f9a
--- /dev/null
+++ b/gas/testsuite/gas/mach-o/sections-2.d
@@ -0,0 +1,14 @@
+#objdump: -h
+#source: empty.s
+# we should only see a text section by default.
+.*: +file format mach-o.*
+#...
+Idx Name.*
+  0 .text.*
+.*
+#failif
+  1 .data.*
+.*
+  2 .bss.*
+.*
+

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

* Re: Rebased : [Patch mach-o  3/3] section directives needed to support GCC
  2011-12-14 16:06           ` Iain Sandoe
@ 2011-12-29 10:58             ` Iain Sandoe
  0 siblings, 0 replies; 9+ messages in thread
From: Iain Sandoe @ 2011-12-29 10:58 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils Development


On 14 Dec 2011, at 16:05, Iain Sandoe wrote:
> On 14 Dec 2011, at 15:38, Tristan Gingold wrote:
>>>
>>>> Anyway, as Alan has approved your changes, I am ok with them.
>>>
>>> ... here is the rebased patch anyway …
>>
>> Last minute minor issue: local variable in obj-macho.c.  See below.
>
> I assume that the var might need to become global at the point that  
> we implement parsing for the the c/l switch .. but it might as well  
> be static for now.
>
> done.. and also, as bonus, the seen_objc_ one before.

applied.
Iain

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

end of thread, other threads:[~2011-12-29 10:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-13  2:23 [Patch mach-o 3/3] section directives needed to support GCC Iain Sandoe
2011-12-13  9:50 ` Tristan Gingold
2011-12-13 10:01   ` Iain Sandoe
2011-12-13 10:38     ` Tristan Gingold
2011-12-13 14:09       ` Rebased : " Iain Sandoe
2011-12-14 15:38         ` Tristan Gingold
2011-12-14 16:06           ` Iain Sandoe
2011-12-29 10:58             ` Iain Sandoe
2011-12-13 10:29   ` 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).