public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR61123 : Fix the ABI mis-matching error caused by LTO
@ 2014-06-18  8:14 Hale Wang
  2014-06-18 10:21 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Hale Wang @ 2014-06-18  8:14 UTC (permalink / raw)
  To: gcc-patches

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

Hi,

With LTO, -fno-short-enums is ignored, resulting in ABI mis-matching in
linking.

Refer https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61123  for details. 

This patch add fshort-enums and fshout-wchar to LTO group.

To check it, a new procedure object-readelf is added in
testsuite/lib/lto.exp and new lto tests are added in gcc.target/arm/lto.

Bootstrap and no make check regression on X86-64.

Patch also attached for convenience.  Is It ok for trunk?

Thanks and Best Regards,
Hale Wang

c-family/ChangeLog
2014-06-18 Hale Wang <hale.wang@arm.com>

                    PR lto/61123
                    *c.opt (fshort-enums): Add to LTO.
                    *c.opt (fshort-wchar): Likewise.

testsuite/ChangeLog
2014-06-18 Hale Wang <hale.wang@arm.com>

                    * gcc.target/arm/lto/: New folder to verify the LTO
option for ARM specific.
                    * gcc.target/arm/lto/pr61123-enum-size_0.c: New test
case.
                    * gcc.target/arm/lto/pr61123-enum-size_1.c: Likewise.
                    * gcc.target/arm/lto/lto.exp: New exp file used to test
LTO option for ARM specific.
                    * lib/lto.exp (object-readelf): New procedure used to
catch the enum size in the final executable.

Index: gcc/c-family/c.opt
===================================================================
--- gcc/c-family/c.opt     (revision 211394)
+++ gcc/c-family/c.opt  (working copy)
@@ -1189,11 +1189,11 @@
Use the same size for double as for float

 fshort-enums
-C ObjC C++ ObjC++ Optimization Var(flag_short_enums)
+C ObjC C++ ObjC++ LTO Optimization Var(flag_short_enums)
Use the narrowest integer type possible for enumeration types

 fshort-wchar
-C ObjC C++ ObjC++ Optimization Var(flag_short_wchar)
+C ObjC C++ ObjC++ LTO Optimization Var(flag_short_wchar)
Force the underlying type for \"wchar_t\" to be \"unsigned short\"

 fsigned-bitfields
Index: gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c
===================================================================
--- gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c       (revision
0)
+++ gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c    (revision 0)
@@ -0,0 +1,22 @@
+/* { dg-lto-do link } */
+/* { dg-lto-options { { -fno-short-enums -Wl,-Ur,--no-enum-size-warning -Os
-nostdlib -flto } } } */
+
+#include <stdlib.h>
+
+enum enum_size_attribute
+{
+  small_size, int_size
+};
+
+struct debug_ABI_enum_size
+{
+  enum enum_size_attribute es;
+};
+
+int
+foo1 (struct debug_ABI_enum_size *x)
+{
+  return sizeof (x->es);
+}
+
+/* { dg-final { object-readelf Tag_ABI_enum_size int { target arm_eabi } }
} */
Index: gcc/testsuite/gcc.target/arm/lto/lto.exp
===================================================================
--- gcc/testsuite/gcc.target/arm/lto/lto.exp        (revision 0)
+++ gcc/testsuite/gcc.target/arm/lto/lto.exp     (revision 0)
@@ -0,0 +1,59 @@
+# Copyright (C) 2009-2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+#
+# Contributed by Diego Novillo <dnovillo@google.com>
+
+
+# Test link-time optimization across multiple files.
+#
+# Programs are broken into multiple files.  Each one is compiled
+# separately with LTO information.  The final executable is generated
+# by collecting all the generated object files using regular LTO or WHOPR.
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+# Load procedures from common libraries.
+load_lib standard.exp
+load_lib gcc.exp
+
+# Load the language-independent compabibility support procedures.
+load_lib lto.exp
+
+# If LTO has not been enabled, bail.
+if { ![check_effective_target_lto] } {
+    return
+}
+
+gcc_init
+lto_init no-mathlib
+
+# Define an identifier for use with this suite to avoid name conflicts
+# with other lto tests running at the same time.
+set sid "c_lto"
+
+# Main loop.
+foreach src [lsort [find $srcdir/$subdir *_0.c]] {
+    # If we're only testing specific files and this isn't one of them, skip
it.
+    if ![runtest_file_p $runtests $src] then {
+             continue
+    }
+
+    lto-execute $src $sid
+}
+
+lto_finish
Index: gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c
===================================================================
--- gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c       (revision
0)
+++ gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c    (revision 0)
@@ -0,0 +1,5 @@
+int
+foo2 (int y)
+{
+  return y*10;
+}
Index: gcc/testsuite/lib/lto.exp
===================================================================
--- gcc/testsuite/lib/lto.exp         (revision 211394)
+++ gcc/testsuite/lib/lto.exp      (working copy)
@@ -650,3 +650,82 @@
               fail "scan-symbol $args"
     }
}
+
+# Call pass if object readelf is ok, otherwise fail.
+# example: /* { dg-final { object-readelf Tag_ABI_enum_size int} } */
+proc object-readelf { args } {
+    global readelf
+    global base_dir
+             upvar 2 execname execname
+
+    if { [llength $args] < 2 } {
+                             error "object-readelf: too few arguments"
+        return
+    }
+    if { [llength $args] > 3 } {
+                             error "object-readelf: too many arguments"
+                             return
+    }
+    if { [llength $args] >= 3 } {
+             switch [dg-process-target [lindex $args 2]] {
+                 "S" { }
+                 "N" { return }
+                 "F" { setup_xfail "*-*-*" }
+                 "P" { }
+             }
+    }
+
+    # Find size like we find g++ in g++.exp.
+    if ![info exists readelf]  {
+             set readelf [findfile $base_dir/../../../binutils/readelf \
+                               $base_dir/../../../binutils/readelf \
+                               [findfile $base_dir/../../readelf
$base_dir/../../readelf \
+                                [findfile $base_dir/readelf
$base_dir/readelf \
+                                 [transform readelf]]]]
+             verbose -log "readelf is $readelf"
+    }
+
+    set what [lindex $args 0]
+             set with [lindex $args 1]
+
+    if ![file_on_host exists $execname] {
+             verbose -log "$execname does not exist"
+             unresolved "object-readelf $what "
+             return
+    }
+
+    set output [remote_exec host "$readelf -A" "$execname"]
+    set status [lindex $output 0]
+    if { $status != 0 } {
+        verbose -log "object-readelf: $readelf failed"
+        unresolved "object-readelf $what $execname"
+        return
+    }
+
+    set text [lindex $output 1]
+    set lines [split $text "\n"]
+
+             set done 0
+             set i 0
+             while { !$done } {
+                             set line_tex [lindex $lines $i]
+                             if { [llength ${line_tex}] > 1} {
+                                             incr i
+                                             if [regexp -- $what $line_tex]
{
+                                                             set match
[regexp -- $with $line_tex]
+                                                             set done 1
+                                             }
+                             } else {
+                                             set done 1
+                             }
+             }
+
+    verbose -log "$what size is $with;"
+    if { $match == 1 } {
+             pass "object-readelf $what size is correct."
+    } else {
+             fail "object-readelf $what size is incorrect."
+    }
+}
+
+

[-- Attachment #2: ABI-mismatching-lto.patch --]
[-- Type: application/octet-stream, Size: 5990 bytes --]

Index: gcc/c-family/c.opt
===================================================================
--- gcc/c-family/c.opt	(revision 211394)
+++ gcc/c-family/c.opt	(working copy)
@@ -1189,11 +1189,11 @@
 Use the same size for double as for float
 
 fshort-enums
-C ObjC C++ ObjC++ Optimization Var(flag_short_enums)
+C ObjC C++ ObjC++ LTO Optimization Var(flag_short_enums)
 Use the narrowest integer type possible for enumeration types
 
 fshort-wchar
-C ObjC C++ ObjC++ Optimization Var(flag_short_wchar)
+C ObjC C++ ObjC++ LTO Optimization Var(flag_short_wchar)
 Force the underlying type for \"wchar_t\" to be \"unsigned short\"
 
 fsigned-bitfields
Index: gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c
===================================================================
--- gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c	(revision 0)
@@ -0,0 +1,22 @@
+/* { dg-lto-do link } */
+/* { dg-lto-options { { -fno-short-enums -Wl,-Ur,--no-enum-size-warning -Os -nostdlib -flto } } } */
+
+#include <stdlib.h>
+
+enum enum_size_attribute
+{
+  small_size, int_size
+};
+
+struct debug_ABI_enum_size
+{
+  enum enum_size_attribute es;
+};
+
+int
+foo1 (struct debug_ABI_enum_size *x)
+{
+  return sizeof (x->es);
+}
+
+/* { dg-final { object-readelf Tag_ABI_enum_size int { target arm_eabi } } } */
Index: gcc/testsuite/gcc.target/arm/lto/lto.exp
===================================================================
--- gcc/testsuite/gcc.target/arm/lto/lto.exp	(revision 0)
+++ gcc/testsuite/gcc.target/arm/lto/lto.exp	(revision 0)
@@ -0,0 +1,59 @@
+# Copyright (C) 2009-2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+#
+# Contributed by Diego Novillo <dnovillo@google.com>
+
+
+# Test link-time optimization across multiple files.
+#
+# Programs are broken into multiple files.  Each one is compiled
+# separately with LTO information.  The final executable is generated
+# by collecting all the generated object files using regular LTO or WHOPR.
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+# Load procedures from common libraries.
+load_lib standard.exp
+load_lib gcc.exp
+
+# Load the language-independent compabibility support procedures.
+load_lib lto.exp
+
+# If LTO has not been enabled, bail.
+if { ![check_effective_target_lto] } {
+    return
+}
+
+gcc_init
+lto_init no-mathlib
+
+# Define an identifier for use with this suite to avoid name conflicts
+# with other lto tests running at the same time.
+set sid "c_lto"
+
+# Main loop.
+foreach src [lsort [find $srcdir/$subdir *_0.c]] {
+    # If we're only testing specific files and this isn't one of them, skip it.
+    if ![runtest_file_p $runtests $src] then {
+	continue
+    }
+
+    lto-execute $src $sid
+}
+
+lto_finish
Index: gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c
===================================================================
--- gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c	(revision 0)
@@ -0,0 +1,5 @@
+int
+foo2 (int y)
+{
+  return y*10;
+}
Index: gcc/testsuite/lib/lto.exp
===================================================================
--- gcc/testsuite/lib/lto.exp	(revision 211394)
+++ gcc/testsuite/lib/lto.exp	(working copy)
@@ -650,3 +650,82 @@
 	fail "scan-symbol $args"
     }
 }
+
+# Call pass if object readelf is ok, otherwise fail.
+# example: /* { dg-final { object-readelf Tag_ABI_enum_size int} } */
+proc object-readelf { args } {
+    global readelf
+    global base_dir
+	upvar 2 execname execname
+
+    if { [llength $args] < 2 } {
+		error "object-readelf: too few arguments"
+        return
+    }
+    if { [llength $args] > 3 } {
+		error "object-readelf: too many arguments"
+		return
+    }
+    if { [llength $args] >= 3 } {
+	switch [dg-process-target [lindex $args 2]] {
+	    "S" { }
+	    "N" { return }
+	    "F" { setup_xfail "*-*-*" }
+	    "P" { }
+	}
+    }
+
+    # Find size like we find g++ in g++.exp.
+    if ![info exists readelf]  {
+	set readelf [findfile $base_dir/../../../binutils/readelf \
+		  $base_dir/../../../binutils/readelf \
+		  [findfile $base_dir/../../readelf $base_dir/../../readelf \
+		   [findfile $base_dir/readelf $base_dir/readelf \
+		    [transform readelf]]]]
+	verbose -log "readelf is $readelf"
+    }
+
+    set what [lindex $args 0]
+	set with [lindex $args 1]
+
+    if ![file_on_host exists $execname] {
+	verbose -log "$execname does not exist"
+	unresolved "object-readelf $what "
+	return
+    }
+
+    set output [remote_exec host "$readelf -A" "$execname"]
+    set status [lindex $output 0]
+    if { $status != 0 } {
+        verbose -log "object-readelf: $readelf failed"
+        unresolved "object-readelf $what $execname"
+        return
+    }
+
+    set text [lindex $output 1]
+    set lines [split $text "\n"]
+
+	set done 0
+	set i 0
+	while { !$done } {
+		set line_tex [lindex $lines $i]
+		if { [llength ${line_tex}] > 1} {
+			incr i
+			if [regexp -- $what $line_tex] {
+				set match [regexp -- $with $line_tex]
+				set done 1
+			}
+		} else {
+			set done 1
+		}
+	}
+
+    verbose -log "$what size is $with;"
+    if { $match == 1 } {
+	pass "object-readelf $what size is correct."
+    } else {
+	fail "object-readelf $what size is incorrect."
+    }
+}
+
+

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

* Re: [PATCH] PR61123 : Fix the ABI mis-matching error caused by LTO
  2014-06-18  8:14 [PATCH] PR61123 : Fix the ABI mis-matching error caused by LTO Hale Wang
@ 2014-06-18 10:21 ` Richard Biener
  2014-06-18 10:22   ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2014-06-18 10:21 UTC (permalink / raw)
  To: Hale Wang; +Cc: GCC Patches

On Wed, Jun 18, 2014 at 10:14 AM, Hale Wang <Hale.Wang@arm.com> wrote:
> Hi,
>
> With LTO, -fno-short-enums is ignored, resulting in ABI mis-matching in
> linking.
>
> Refer https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61123  for details.
>
> This patch add fshort-enums and fshout-wchar to LTO group.
>
> To check it, a new procedure object-readelf is added in
> testsuite/lib/lto.exp and new lto tests are added in gcc.target/arm/lto.
>
> Bootstrap and no make check regression on X86-64.
>
> Patch also attached for convenience.  Is It ok for trunk?
>
> Thanks and Best Regards,
> Hale Wang
>
> c-family/ChangeLog
> 2014-06-18 Hale Wang <hale.wang@arm.com>
>
>                     PR lto/61123
>                     *c.opt (fshort-enums): Add to LTO.
>                     *c.opt (fshort-wchar): Likewise.

Space after the *.

I think you don't need to copy the LTO harness but you can simply
use dg.exp and sth similar to gcc.dg/20081223-1.c (there is an
effective target 'lto' to guard for lto support).

So simply place the testcase in gcc.target/arm/ (make sure to
put a dg-do compile on the 2nd file and use dg-additional-sources).

If that doesn't work I'd say put the testcase in gcc.dg/lto/ instead
and do a dg-skip-if for non-arm targets.

Ok with one of those changes.

Thanks,
Richard.

> testsuite/ChangeLog
> 2014-06-18 Hale Wang <hale.wang@arm.com>
>
>                     * gcc.target/arm/lto/: New folder to verify the LTO
> option for ARM specific.
>                     * gcc.target/arm/lto/pr61123-enum-size_0.c: New test
> case.
>                     * gcc.target/arm/lto/pr61123-enum-size_1.c: Likewise.
>                     * gcc.target/arm/lto/lto.exp: New exp file used to test
> LTO option for ARM specific.
>                     * lib/lto.exp (object-readelf): New procedure used to
> catch the enum size in the final executable.
>
> Index: gcc/c-family/c.opt
> ===================================================================
> --- gcc/c-family/c.opt     (revision 211394)
> +++ gcc/c-family/c.opt  (working copy)
> @@ -1189,11 +1189,11 @@
> Use the same size for double as for float
>
>  fshort-enums
> -C ObjC C++ ObjC++ Optimization Var(flag_short_enums)
> +C ObjC C++ ObjC++ LTO Optimization Var(flag_short_enums)
> Use the narrowest integer type possible for enumeration types
>
>  fshort-wchar
> -C ObjC C++ ObjC++ Optimization Var(flag_short_wchar)
> +C ObjC C++ ObjC++ LTO Optimization Var(flag_short_wchar)
> Force the underlying type for \"wchar_t\" to be \"unsigned short\"
>
>  fsigned-bitfields
> Index: gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c
> ===================================================================
> --- gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c       (revision
> 0)
> +++ gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c    (revision 0)
> @@ -0,0 +1,22 @@
> +/* { dg-lto-do link } */
> +/* { dg-lto-options { { -fno-short-enums -Wl,-Ur,--no-enum-size-warning -Os
> -nostdlib -flto } } } */
> +
> +#include <stdlib.h>
> +
> +enum enum_size_attribute
> +{
> +  small_size, int_size
> +};
> +
> +struct debug_ABI_enum_size
> +{
> +  enum enum_size_attribute es;
> +};
> +
> +int
> +foo1 (struct debug_ABI_enum_size *x)
> +{
> +  return sizeof (x->es);
> +}
> +
> +/* { dg-final { object-readelf Tag_ABI_enum_size int { target arm_eabi } }
> } */
> Index: gcc/testsuite/gcc.target/arm/lto/lto.exp
> ===================================================================
> --- gcc/testsuite/gcc.target/arm/lto/lto.exp        (revision 0)
> +++ gcc/testsuite/gcc.target/arm/lto/lto.exp     (revision 0)
> @@ -0,0 +1,59 @@
> +# Copyright (C) 2009-2014 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with GCC; see the file COPYING3.  If not see
> +# <http://www.gnu.org/licenses/>.
> +#
> +# Contributed by Diego Novillo <dnovillo@google.com>
> +
> +
> +# Test link-time optimization across multiple files.
> +#
> +# Programs are broken into multiple files.  Each one is compiled
> +# separately with LTO information.  The final executable is generated
> +# by collecting all the generated object files using regular LTO or WHOPR.
> +
> +if $tracelevel then {
> +    strace $tracelevel
> +}
> +
> +# Load procedures from common libraries.
> +load_lib standard.exp
> +load_lib gcc.exp
> +
> +# Load the language-independent compabibility support procedures.
> +load_lib lto.exp
> +
> +# If LTO has not been enabled, bail.
> +if { ![check_effective_target_lto] } {
> +    return
> +}
> +
> +gcc_init
> +lto_init no-mathlib
> +
> +# Define an identifier for use with this suite to avoid name conflicts
> +# with other lto tests running at the same time.
> +set sid "c_lto"
> +
> +# Main loop.
> +foreach src [lsort [find $srcdir/$subdir *_0.c]] {
> +    # If we're only testing specific files and this isn't one of them, skip
> it.
> +    if ![runtest_file_p $runtests $src] then {
> +             continue
> +    }
> +
> +    lto-execute $src $sid
> +}
> +
> +lto_finish
> Index: gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c
> ===================================================================
> --- gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c       (revision
> 0)
> +++ gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c    (revision 0)
> @@ -0,0 +1,5 @@
> +int
> +foo2 (int y)
> +{
> +  return y*10;
> +}
> Index: gcc/testsuite/lib/lto.exp
> ===================================================================
> --- gcc/testsuite/lib/lto.exp         (revision 211394)
> +++ gcc/testsuite/lib/lto.exp      (working copy)
> @@ -650,3 +650,82 @@
>                fail "scan-symbol $args"
>      }
> }
> +
> +# Call pass if object readelf is ok, otherwise fail.
> +# example: /* { dg-final { object-readelf Tag_ABI_enum_size int} } */
> +proc object-readelf { args } {
> +    global readelf
> +    global base_dir
> +             upvar 2 execname execname
> +
> +    if { [llength $args] < 2 } {
> +                             error "object-readelf: too few arguments"
> +        return
> +    }
> +    if { [llength $args] > 3 } {
> +                             error "object-readelf: too many arguments"
> +                             return
> +    }
> +    if { [llength $args] >= 3 } {
> +             switch [dg-process-target [lindex $args 2]] {
> +                 "S" { }
> +                 "N" { return }
> +                 "F" { setup_xfail "*-*-*" }
> +                 "P" { }
> +             }
> +    }
> +
> +    # Find size like we find g++ in g++.exp.
> +    if ![info exists readelf]  {
> +             set readelf [findfile $base_dir/../../../binutils/readelf \
> +                               $base_dir/../../../binutils/readelf \
> +                               [findfile $base_dir/../../readelf
> $base_dir/../../readelf \
> +                                [findfile $base_dir/readelf
> $base_dir/readelf \
> +                                 [transform readelf]]]]
> +             verbose -log "readelf is $readelf"
> +    }
> +
> +    set what [lindex $args 0]
> +             set with [lindex $args 1]
> +
> +    if ![file_on_host exists $execname] {
> +             verbose -log "$execname does not exist"
> +             unresolved "object-readelf $what "
> +             return
> +    }
> +
> +    set output [remote_exec host "$readelf -A" "$execname"]
> +    set status [lindex $output 0]
> +    if { $status != 0 } {
> +        verbose -log "object-readelf: $readelf failed"
> +        unresolved "object-readelf $what $execname"
> +        return
> +    }
> +
> +    set text [lindex $output 1]
> +    set lines [split $text "\n"]
> +
> +             set done 0
> +             set i 0
> +             while { !$done } {
> +                             set line_tex [lindex $lines $i]
> +                             if { [llength ${line_tex}] > 1} {
> +                                             incr i
> +                                             if [regexp -- $what $line_tex]
> {
> +                                                             set match
> [regexp -- $with $line_tex]
> +                                                             set done 1
> +                                             }
> +                             } else {
> +                                             set done 1
> +                             }
> +             }
> +
> +    verbose -log "$what size is $with;"
> +    if { $match == 1 } {
> +             pass "object-readelf $what size is correct."
> +    } else {
> +             fail "object-readelf $what size is incorrect."
> +    }
> +}
> +
> +

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

* Re: [PATCH] PR61123 : Fix the ABI mis-matching error caused by LTO
  2014-06-18 10:21 ` Richard Biener
@ 2014-06-18 10:22   ` Richard Biener
  2014-06-18 17:41     ` Mike Stump
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2014-06-18 10:22 UTC (permalink / raw)
  To: Hale Wang, Mike Stump; +Cc: GCC Patches

On Wed, Jun 18, 2014 at 12:21 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Wed, Jun 18, 2014 at 10:14 AM, Hale Wang <Hale.Wang@arm.com> wrote:
>> Hi,
>>
>> With LTO, -fno-short-enums is ignored, resulting in ABI mis-matching in
>> linking.
>>
>> Refer https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61123  for details.
>>
>> This patch add fshort-enums and fshout-wchar to LTO group.
>>
>> To check it, a new procedure object-readelf is added in
>> testsuite/lib/lto.exp and new lto tests are added in gcc.target/arm/lto.
>>
>> Bootstrap and no make check regression on X86-64.
>>
>> Patch also attached for convenience.  Is It ok for trunk?
>>
>> Thanks and Best Regards,
>> Hale Wang
>>
>> c-family/ChangeLog
>> 2014-06-18 Hale Wang <hale.wang@arm.com>
>>
>>                     PR lto/61123
>>                     *c.opt (fshort-enums): Add to LTO.
>>                     *c.opt (fshort-wchar): Likewise.
>
> Space after the *.
>
> I think you don't need to copy the LTO harness but you can simply
> use dg.exp and sth similar to gcc.dg/20081223-1.c (there is an
> effective target 'lto' to guard for lto support).
>
> So simply place the testcase in gcc.target/arm/ (make sure to
> put a dg-do compile on the 2nd file and use dg-additional-sources).
>
> If that doesn't work I'd say put the testcase in gcc.dg/lto/ instead
> and do a dg-skip-if for non-arm targets.
>
> Ok with one of those changes.

Oh, I see you need a new object-readelf ... I defer to a testsuite maintainer
for this part.

Richard.

> Thanks,
> Richard.
>
>> testsuite/ChangeLog
>> 2014-06-18 Hale Wang <hale.wang@arm.com>
>>
>>                     * gcc.target/arm/lto/: New folder to verify the LTO
>> option for ARM specific.
>>                     * gcc.target/arm/lto/pr61123-enum-size_0.c: New test
>> case.
>>                     * gcc.target/arm/lto/pr61123-enum-size_1.c: Likewise.
>>                     * gcc.target/arm/lto/lto.exp: New exp file used to test
>> LTO option for ARM specific.
>>                     * lib/lto.exp (object-readelf): New procedure used to
>> catch the enum size in the final executable.
>>
>> Index: gcc/c-family/c.opt
>> ===================================================================
>> --- gcc/c-family/c.opt     (revision 211394)
>> +++ gcc/c-family/c.opt  (working copy)
>> @@ -1189,11 +1189,11 @@
>> Use the same size for double as for float
>>
>>  fshort-enums
>> -C ObjC C++ ObjC++ Optimization Var(flag_short_enums)
>> +C ObjC C++ ObjC++ LTO Optimization Var(flag_short_enums)
>> Use the narrowest integer type possible for enumeration types
>>
>>  fshort-wchar
>> -C ObjC C++ ObjC++ Optimization Var(flag_short_wchar)
>> +C ObjC C++ ObjC++ LTO Optimization Var(flag_short_wchar)
>> Force the underlying type for \"wchar_t\" to be \"unsigned short\"
>>
>>  fsigned-bitfields
>> Index: gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c
>> ===================================================================
>> --- gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c       (revision
>> 0)
>> +++ gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_0.c    (revision 0)
>> @@ -0,0 +1,22 @@
>> +/* { dg-lto-do link } */
>> +/* { dg-lto-options { { -fno-short-enums -Wl,-Ur,--no-enum-size-warning -Os
>> -nostdlib -flto } } } */
>> +
>> +#include <stdlib.h>
>> +
>> +enum enum_size_attribute
>> +{
>> +  small_size, int_size
>> +};
>> +
>> +struct debug_ABI_enum_size
>> +{
>> +  enum enum_size_attribute es;
>> +};
>> +
>> +int
>> +foo1 (struct debug_ABI_enum_size *x)
>> +{
>> +  return sizeof (x->es);
>> +}
>> +
>> +/* { dg-final { object-readelf Tag_ABI_enum_size int { target arm_eabi } }
>> } */
>> Index: gcc/testsuite/gcc.target/arm/lto/lto.exp
>> ===================================================================
>> --- gcc/testsuite/gcc.target/arm/lto/lto.exp        (revision 0)
>> +++ gcc/testsuite/gcc.target/arm/lto/lto.exp     (revision 0)
>> @@ -0,0 +1,59 @@
>> +# Copyright (C) 2009-2014 Free Software Foundation, Inc.
>> +
>> +# This program is free software; you can redistribute it and/or modify
>> +# it under the terms of the GNU General Public License as published by
>> +# the Free Software Foundation; either version 3 of the License, or
>> +# (at your option) any later version.
>> +#
>> +# This program is distributed in the hope that it will be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +# GNU General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU General Public License
>> +# along with GCC; see the file COPYING3.  If not see
>> +# <http://www.gnu.org/licenses/>.
>> +#
>> +# Contributed by Diego Novillo <dnovillo@google.com>
>> +
>> +
>> +# Test link-time optimization across multiple files.
>> +#
>> +# Programs are broken into multiple files.  Each one is compiled
>> +# separately with LTO information.  The final executable is generated
>> +# by collecting all the generated object files using regular LTO or WHOPR.
>> +
>> +if $tracelevel then {
>> +    strace $tracelevel
>> +}
>> +
>> +# Load procedures from common libraries.
>> +load_lib standard.exp
>> +load_lib gcc.exp
>> +
>> +# Load the language-independent compabibility support procedures.
>> +load_lib lto.exp
>> +
>> +# If LTO has not been enabled, bail.
>> +if { ![check_effective_target_lto] } {
>> +    return
>> +}
>> +
>> +gcc_init
>> +lto_init no-mathlib
>> +
>> +# Define an identifier for use with this suite to avoid name conflicts
>> +# with other lto tests running at the same time.
>> +set sid "c_lto"
>> +
>> +# Main loop.
>> +foreach src [lsort [find $srcdir/$subdir *_0.c]] {
>> +    # If we're only testing specific files and this isn't one of them, skip
>> it.
>> +    if ![runtest_file_p $runtests $src] then {
>> +             continue
>> +    }
>> +
>> +    lto-execute $src $sid
>> +}
>> +
>> +lto_finish
>> Index: gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c
>> ===================================================================
>> --- gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c       (revision
>> 0)
>> +++ gcc/testsuite/gcc.target/arm/lto/pr61123-enum-size_1.c    (revision 0)
>> @@ -0,0 +1,5 @@
>> +int
>> +foo2 (int y)
>> +{
>> +  return y*10;
>> +}
>> Index: gcc/testsuite/lib/lto.exp
>> ===================================================================
>> --- gcc/testsuite/lib/lto.exp         (revision 211394)
>> +++ gcc/testsuite/lib/lto.exp      (working copy)
>> @@ -650,3 +650,82 @@
>>                fail "scan-symbol $args"
>>      }
>> }
>> +
>> +# Call pass if object readelf is ok, otherwise fail.
>> +# example: /* { dg-final { object-readelf Tag_ABI_enum_size int} } */
>> +proc object-readelf { args } {
>> +    global readelf
>> +    global base_dir
>> +             upvar 2 execname execname
>> +
>> +    if { [llength $args] < 2 } {
>> +                             error "object-readelf: too few arguments"
>> +        return
>> +    }
>> +    if { [llength $args] > 3 } {
>> +                             error "object-readelf: too many arguments"
>> +                             return
>> +    }
>> +    if { [llength $args] >= 3 } {
>> +             switch [dg-process-target [lindex $args 2]] {
>> +                 "S" { }
>> +                 "N" { return }
>> +                 "F" { setup_xfail "*-*-*" }
>> +                 "P" { }
>> +             }
>> +    }
>> +
>> +    # Find size like we find g++ in g++.exp.
>> +    if ![info exists readelf]  {
>> +             set readelf [findfile $base_dir/../../../binutils/readelf \
>> +                               $base_dir/../../../binutils/readelf \
>> +                               [findfile $base_dir/../../readelf
>> $base_dir/../../readelf \
>> +                                [findfile $base_dir/readelf
>> $base_dir/readelf \
>> +                                 [transform readelf]]]]
>> +             verbose -log "readelf is $readelf"
>> +    }
>> +
>> +    set what [lindex $args 0]
>> +             set with [lindex $args 1]
>> +
>> +    if ![file_on_host exists $execname] {
>> +             verbose -log "$execname does not exist"
>> +             unresolved "object-readelf $what "
>> +             return
>> +    }
>> +
>> +    set output [remote_exec host "$readelf -A" "$execname"]
>> +    set status [lindex $output 0]
>> +    if { $status != 0 } {
>> +        verbose -log "object-readelf: $readelf failed"
>> +        unresolved "object-readelf $what $execname"
>> +        return
>> +    }
>> +
>> +    set text [lindex $output 1]
>> +    set lines [split $text "\n"]
>> +
>> +             set done 0
>> +             set i 0
>> +             while { !$done } {
>> +                             set line_tex [lindex $lines $i]
>> +                             if { [llength ${line_tex}] > 1} {
>> +                                             incr i
>> +                                             if [regexp -- $what $line_tex]
>> {
>> +                                                             set match
>> [regexp -- $with $line_tex]
>> +                                                             set done 1
>> +                                             }
>> +                             } else {
>> +                                             set done 1
>> +                             }
>> +             }
>> +
>> +    verbose -log "$what size is $with;"
>> +    if { $match == 1 } {
>> +             pass "object-readelf $what size is correct."
>> +    } else {
>> +             fail "object-readelf $what size is incorrect."
>> +    }
>> +}
>> +
>> +

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

* Re: [PATCH] PR61123 : Fix the ABI mis-matching error caused by LTO
  2014-06-18 10:22   ` Richard Biener
@ 2014-06-18 17:41     ` Mike Stump
  0 siblings, 0 replies; 4+ messages in thread
From: Mike Stump @ 2014-06-18 17:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: Hale Wang, Mike Stump, GCC Patches

On Jun 18, 2014, at 3:22 AM, Richard Biener <richard.guenther@gmail.com> wrote:
>> Space after the *.
>> 
>> I think you don't need to copy the LTO harness but you can simply
>> use dg.exp and sth similar to gcc.dg/20081223-1.c (there is an
>> effective target 'lto' to guard for lto support).
>> 
>> So simply place the testcase in gcc.target/arm/ (make sure to
>> put a dg-do compile on the 2nd file and use dg-additional-sources).
>> 
>> If that doesn't work I'd say put the testcase in gcc.dg/lto/ instead
>> and do a dg-skip-if for non-arm targets.
>> 
>> Ok with one of those changes.
> 
> Oh, I see you need a new object-readelf ... I defer to a testsuite maintainer
> for this part.

The testsuite bits are Ok.  My guidance on the test suite would be this, all lto test cases in .*lto directories.  20 or fewer test cases for a given target, in the main lto directory, more than 50, in the arm/lto directory.  When one is tracking down bugs and trying to clean test suite results if they break, it is nice to be able to skip in mass all lto bugs first, and resolve all non-lto issues and then come back to the lto issues last, in hopes that they are all then resolved.  Also, if one it redoing lto bits, and a test case with lto in the name pops up as a regression, and you’re not an lto person, you can stop thinking about it and just pass to the lto person, it is a slightly different mindset.  :-)

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

end of thread, other threads:[~2014-06-18 17:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-18  8:14 [PATCH] PR61123 : Fix the ABI mis-matching error caused by LTO Hale Wang
2014-06-18 10:21 ` Richard Biener
2014-06-18 10:22   ` Richard Biener
2014-06-18 17:41     ` Mike Stump

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).