[testsuite] Fix PR78544 for Darwin.

Message ID DDEB1408-BBEE-4B2A-9E25-9C00A3D5E6A8@sandoe.co.uk
State New
Headers show
Series
  • [testsuite] Fix PR78544 for Darwin.
Related show

Commit Message

Iain Sandoe Aug. 15, 2018, 1:20 p.m.
Hi,

The fails on Darwin are because the section naming convention is different.

The patch adds Darwin-specific section attributes and a corresponding target-specific scan-assembler clause.

OK for trunk?
affected branches (7, 8)?

thanks
Iain

2018-08-15  Iain Sandoe <iain@sandoe.co.uk>

gcc/testsuite:

	PR testsuite/78544
	* gcc.dg/tree-prof/section-attr-1.c: Add Darwin-specific section attributes and matching.
	* gcc.dg/tree-prof/section-attr-2.c: Likewise.
	* gcc.dg/tree-prof/section-attr-3.c: Likewise.

---
 gcc/testsuite/gcc.dg/tree-prof/section-attr-1.c | 5 +++++
 gcc/testsuite/gcc.dg/tree-prof/section-attr-2.c | 5 +++++
 gcc/testsuite/gcc.dg/tree-prof/section-attr-3.c | 5 +++++
 3 files changed, 15 insertions(+)

-- 
2.17.1

Comments

Mike Stump Aug. 15, 2018, 6:39 p.m. | #1
On Aug 15, 2018, at 6:20 AM, Iain Sandoe <iain@sandoe.co.uk> wrote:
> 

> The fails on Darwin are because the section naming convention is different.

> 

> The patch adds Darwin-specific section attributes and a corresponding target-specific scan-assembler clause.

> 

> OK for trunk?

> affected branches (7, 8)?


Ok.

[ just thinking out loud ] It might be nice to have a section name mapper that can convert section names from the rest of the world, into darwin style section names.  .text -> __TEXT,__text and so on, then some of this patch can be backed out as unnecessary. The point of the patch would be to increase the portability of code to the platform.  The other possibility would be for darwin to just add support for all the usual elf things and for those all to work.
Iain Sandoe Aug. 15, 2018, 6:48 p.m. | #2
> On 15 Aug 2018, at 19:39, Mike Stump <mikestump@comcast.net> wrote:

> 

> On Aug 15, 2018, at 6:20 AM, Iain Sandoe <iain@sandoe.co.uk> wrote:

>> 

>> The fails on Darwin are because the section naming convention is different.

>> 

>> The patch adds Darwin-specific section attributes and a corresponding target-specific scan-assembler clause.

>> 

>> OK for trunk?

>> affected branches (7, 8)?

> 

> Ok.

> 

> [ just thinking out loud ] It might be nice to have a section name mapper that can convert section names from the rest of the world, into Darwin style section names.  .text -> __TEXT,__text and so on, then some of this patch can be backed out as unnecessary. The point of the patch would be to increase the portability of code to the platform.  The other possibility would be for darwin to just add support for all the usual elf things and for those all to work.


It’s a good thought - we quite frequently end up fixing “bugs” that are just folks forgetting to add the Darwin-flavour section.

One of my Grand Ideas (i.e. things that might never happen because of time) would be to split out the Well Known Sections used by GCC into file/files with .defs for the different flavours. This would mean one place to add a new GCC named section - which would make it much less likely for folks to forget to add the Darwin ones (assuming there are no targets left without named sections).
Joseph Myers Aug. 15, 2018, 7:07 p.m. | #3
On Wed, 15 Aug 2018, Iain Sandoe wrote:

> One of my Grand Ideas (i.e. things that might never happen because of 

> time) would be to split out the Well Known Sections used by GCC into 

> file/files with .defs for the different flavours. This would mean one 

> place to add a new GCC named section - which would make it much less 

> likely for folks to forget to add the Darwin ones (assuming there are no 

> targets left without named sections).


Targets without named sections are pdp11 and 32-bit PA HP-UX (plus 
m68k-openbsd and vax-openbsd, but I think the non-ELF OpenBSD targets are 
for very old OpenBSD versions, probably long obsolete).

-- 
Joseph S. Myers
joseph@codesourcery.com
Iain Sandoe Aug. 15, 2018, 7:16 p.m. | #4
> On 15 Aug 2018, at 20:07, Joseph Myers <joseph@codesourcery.com> wrote:

> 

> On Wed, 15 Aug 2018, Iain Sandoe wrote:

> 

>> One of my Grand Ideas (i.e. things that might never happen because of 

>> time) would be to split out the Well Known Sections used by GCC into 

>> file/files with .defs for the different flavours. This would mean one 

>> place to add a new GCC named section - which would make it much less 

>> likely for folks to forget to add the Darwin ones (assuming there are no 

>> targets left without named sections).

> 

> Targets without named sections are pdp11 and 32-bit PA HP-UX (plus 

> m68k-openbsd and vax-openbsd, but I think the non-ELF OpenBSD targets are 

> for very old OpenBSD versions, probably long obsolete).


So, I suppose, one would need to make it possible to put .data / .text  to pick the
 “most suitable” substitute for those (I guess somehow that’s already done for
existing generic infra. that uses named sections).

Iain

Patch

diff --git a/gcc/testsuite/gcc.dg/tree-prof/section-attr-1.c b/gcc/testsuite/gcc.dg/tree-prof/section-attr-1.c
index ee6662ea6e..1f99b3128c 100644
--- a/gcc/testsuite/gcc.dg/tree-prof/section-attr-1.c
+++ b/gcc/testsuite/gcc.dg/tree-prof/section-attr-1.c
@@ -13,7 +13,11 @@  const char *buf_cold;
 
 void foo (int path);
 
+#ifdef __APPLE__
+__attribute__ ((section ("__TEXT,__text")))
+#else
 __attribute__((section(".text")))
+#endif
 int
 main (int argc, char *argv[])
 {
@@ -43,3 +47,4 @@  foo (int path)
 }
 
 /* { dg-final-use { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold\.0" { target *-*-linux* *-*-gnu* } } } */
+/* { dg-final-use { scan-assembler "\.section\[\t \]*__TEXT,__text_cold\.\*\[\\n\\r\]+_foo\.cold\.0" { target *-*-darwin* } } } */
diff --git a/gcc/testsuite/gcc.dg/tree-prof/section-attr-2.c b/gcc/testsuite/gcc.dg/tree-prof/section-attr-2.c
index 898a395cd7..9bdc63a1b0 100644
--- a/gcc/testsuite/gcc.dg/tree-prof/section-attr-2.c
+++ b/gcc/testsuite/gcc.dg/tree-prof/section-attr-2.c
@@ -28,7 +28,11 @@  main (int argc, char *argv[])
 void NOINLINE
 foo (int path)
 {
+#ifdef __APPLE__
+  static int i __attribute__ ((section ("__DATA,__data")));
+#else
   static int i __attribute__((section(".data")));
+#endif
   if (path)
     {
       for (i = 0; i < SIZE; i++)
@@ -42,3 +46,4 @@  foo (int path)
 }
 
 /* { dg-final-use { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold\.0" { target *-*-linux* *-*-gnu* } } } */
+/* { dg-final-use { scan-assembler "\.section\[\t \]*__TEXT,__text_cold\.\*\[\\n\\r\]+_foo\.cold\.0:" { target *-*-darwin* } } } */
diff --git a/gcc/testsuite/gcc.dg/tree-prof/section-attr-3.c b/gcc/testsuite/gcc.dg/tree-prof/section-attr-3.c
index 36829dcb7a..29eee4587d 100644
--- a/gcc/testsuite/gcc.dg/tree-prof/section-attr-3.c
+++ b/gcc/testsuite/gcc.dg/tree-prof/section-attr-3.c
@@ -9,7 +9,11 @@ 
 #define NOINLINE __attribute__((noinline)) __attribute__ ((noclone))
 
 const char *sarr[SIZE];
+#ifdef __APPLE__
+const char *buf_hot __attribute__ ((section ("__DATA,__data")));
+#else
 const char *buf_hot __attribute__ ((section (".data")));
+#endif
 const char *buf_cold;
 
 void foo (int path);
@@ -43,3 +47,4 @@  foo (int path)
 }
 
 /* { dg-final-use { scan-assembler "\.section\[\t \]*\.text\.unlikely\[\\n\\r\]+\[\t \]*\.size\[\t \]*foo\.cold\.0" { target *-*-linux* *-*-gnu* } } } */
+/* { dg-final-use { scan-assembler "\.section\[\t \]*__TEXT,__text_cold\.\*\[\\n\\r\]+_foo\.cold\.0:" { target *-*-darwin* } } } */