Bug 52042 - libitm.c/clone-1.c (all darwin) and libitm.c/stackundo.c (darwin 11) execution tests fail with -fpie
Summary: libitm.c/clone-1.c (all darwin) and libitm.c/stackundo.c (darwin 11) executio...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libitm (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-29 17:03 UTC by Jack Howarth
Modified: 2012-02-28 20:27 UTC (History)
5 users (show)

See Also:
Host: *-apple-darwin*
Target: *-apple-darwin*
Build: *-apple-darwin*
Known to work:
Known to fail:
Last reconfirmed: 2012-01-31 00:00:00


Attachments
patch that seems to work for clone-1.c (464 bytes, patch)
2012-02-07 04:02 UTC, Patrick Marlier
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jack Howarth 2012-01-29 17:03:30 UTC
On x86_64-apple-darwin11, the libitm testsuite failures...

FAIL: libitm.c/clone-1.c execution test
FAIL: libitm.c/stackundo.c execution test

are seen at both -m32/-m64. These test cases don't fail within
Apple gdb due to its default disabling of aslr. If aslr is enabled within gdb,
the following backtraces are seen...

gdb ./stackundo.exe
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov  3 21:59:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .... done

(gdb) set disable-aslr off
(gdb) r
Starting program: /sw/src/fink.build/gcc47-4.7.0-1/darwin_objdir/x86_64-apple-darwin11.2.0/libitm/testsuite/stackundo.exe 
Reading symbols for shared libraries + done
Reading symbols for shared libraries ++++........................ done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x00000001000010b0
clone_entry_compare (a=0x1000010a0, b=0x1000010b0) at ../../../gcc-4.7-20120126/libitm/clone.cc:105
105	  if (aa->orig < bb->orig)
(gdb) bt
#0  clone_entry_compare (a=0x1000010a0, b=0x1000010b0) at ../../../gcc-4.7-20120126/libitm/clone.cc:105
#1  0x00007fff8ddd4894 in _qsort ()
#2  0x00000001016948c6 in _ITM_registerTMCloneTable (xent=0x1000010a0, size=2) at ../../../gcc-4.7-20120126/libitm/clone.cc:155
Current language:  auto; currently c++


gdb ./clone-1.exeGNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov  3 21:59:02 UTC 2011)Copyright 2004 Free Software Foundation, Inc.GDB is free software, covered by the GNU General Public License, and you arewelcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .... done

(gdb) set disable-aslr off
(gdb) r
Starting program: /sw/src/fink.build/gcc47-4.7.0-1/darwin_objdir/x86_64-apple-darwin11.2.0/libitm/testsuite/clone-1.exe 
Reading symbols for shared libraries + done
Reading symbols for shared libraries ++++........................ done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x00000001000010a8
clone_entry_compare (a=0x100001098, b=0x1000010a8) at ../../../gcc-4.7-20120126/libitm/clone.cc:105
105	  if (aa->orig < bb->orig)
(gdb) bt
#0  clone_entry_compare (a=0x100001098, b=0x1000010a8) at ../../../gcc-4.7-20120126/libitm/clone.cc:105
#1  0x00007fff8ddd4894 in _qsort ()
#2  0x000000010299a8c6 in _ITM_registerTMCloneTable (xent=0x100001098, size=2) at ../../../gcc-4.7-20120126/libitm/clone.cc:155
Current language:  auto; currently c++

Using built-in specs.
COLLECT_GCC=gcc-fsf-4.7
COLLECT_LTO_WRAPPER=/sw/lib/gcc4.7/libexec/gcc/x86_64-apple-darwin11.2.0/4.7.0/lto-wrapper
Target: x86_64-apple-darwin11.2.0
Configured with: ../gcc-4.7-20120126/configure --prefix=/sw --prefix=/sw/lib/gcc4.7 --mandir=/sw/share/man --infodir=/sw/lib/gcc4.7/info --with-build-config=bootstrap-lto --enable-stage1-languages=c,lto --enable-languages=c,c++,fortran,lto,objc,obj-c++,java --with-gmp=/sw --with-libiconv-prefix=/sw --with-ppl=/sw --with-cloog=/sw --with-mpc=/sw --with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib --program-suffix=-fsf-4.7 --enable-checking=yes --enable-cloog-backend=isl
Thread model: posix
gcc version 4.7.0 20120126 (experimental) (GCC)
Comment 1 Jack Howarth 2012-01-30 18:21:09 UTC
Note that darwin11 leverages the PIC default on darwin to create pie executables by defaulting the linker to -pie when targeting 10.7 or later. The question is whether, like gcc.dg/darwin-segaddr.c, that libitm.c/clone-1.c and libitm.c/stackundo.c are meaningless for pie executables. If so, we should just append -Wl,-no_pie to the flags on those tests as has been done for gcc.dg/darwin-segaddr.c.
Comment 2 mrs@gcc.gnu.org 2012-01-30 19:05:03 UTC
Patch using dg-additional-options pre-approved if these testcases are pie incompatible.
Comment 3 Iain Sandoe 2012-01-31 08:34:33 UTC
on i686-darwin9:
 make check-target-libitm RUNTESTFLAGS="--target_board=unix/-fpie\{-m32,-m64\}"

clone-1 fails (m32, m64), but stackundo passes on both.

I don't know whether clone is incompatible with the concept of a slidable image - or whether we just have a bug to chase down. 
 
Richard?
Comment 4 Iain Sandoe 2012-01-31 13:55:44 UTC
(In reply to comment #3)
> on i686-darwin9:
>  make check-target-libitm RUNTESTFLAGS="--target_board=unix/-fpie\{-m32,-m64\}"
> 
> clone-1 fails (m32, m64), but stackundo passes on both.

this is repeated on {i686,x86-64,powerpc-darwin{9,10}

but clone-1.c passes -fpie on i686-linux (F14) ... I assume that the flag is not ignored.

so, this seems to be a bug  ...
Comment 5 Jack Howarth 2012-01-31 17:54:09 UTC
(In reply to comment #3)
> on i686-darwin9:
>  make check-target-libitm RUNTESTFLAGS="--target_board=unix/-fpie\{-m32,-m64\}"
> 
> clone-1 fails (m32, m64), but stackundo passes on both.
> 

Same results on x86_64 darwin10. Note however that the alsr in Lion is supposed to be
more exhaustive than that in previous releases. It seems from the discussion at...

http://www.0xcafebabe.it/2011/10/15/on-macos-10-7-dyld-randomization/
http://gdtr.wordpress.com/tag/aslr/

that prior to Lion, the dyld image base wasn't randomized for -pie.
Comment 6 Patrick Marlier 2012-02-07 04:02:08 UTC
Created attachment 26595 [details]
patch that seems to work for clone-1.c

Hi guys,

In fact, the problem is that getsectdata doesn't take into account the PIE. We can use _dyld_get_image_vmaddr_slide(0) but it should not be correct in case of many dynamic libraries I guess. What do you think? Should I propose this patch?

Patrick Marlier.
Comment 7 mrs@gcc.gnu.org 2012-02-07 18:17:33 UTC
Yes, love to see a patch.  I think the argument is important to get right, as otherwise the next bug to track down will be much harder to find (I call this bug pushing).  If you can only do part of the job, that's fine, but, please add an assert so that we don't get silently wrong data in cases that aren't handled yet.
Comment 8 Jack Howarth 2012-02-07 21:15:00 UTC
(In reply to comment #7)
While I haven't done a full bootstrap, applying the patch from comment 6 and remaking the current build reduces the libitm failures to just...

FAIL: libitm.c++/eh-1.C execution test

at -m32/-m64 on x86_64-apple-darwin11 so this patch also eliminates the stackundo.c execution failure.
Comment 9 Patrick Marlier 2012-02-08 03:38:24 UTC
Proposed fix here:
http://gcc.gnu.org/ml/gcc-patches/2012-02/msg00321.html

All comments (and tests) are welcome!

Thanks.
Comment 10 pmarlier 2012-02-15 19:17:47 UTC
Author: pmarlier
Date: Wed Feb 15 19:17:42 2012
New Revision: 184281

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=184281
Log:
2012-02-15  Iain Sandoe  <iains@gcc.gnu.org>
	    Patrick Marlier  <patrick.marlier@gmail.com>

	PR libitm/52042
	* config/darwin-crt-tm.c (getTMCloneTable): New function.
	(__doTMRegistrations): Call it.
	(__doTMdeRegistrations): Likewise. 


Modified:
    trunk/libgcc/ChangeLog
    trunk/libgcc/config/darwin-crt-tm.c
Comment 11 mrs@gcc.gnu.org 2012-02-28 20:27:47 UTC
Fixed.