Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-10-23 Thread Marcus Shawcroft
Hi,

This patch breaks the distinction between build and host. For example
consider a configure along these lines:

./configure --host=aarch64-none-linux-gnu
--target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu

Will result in:

CXX_FOR_BUILD='g++'
CXX='aarch64-none-linux-gnu-g++'

the gcc/configure fragment:

+# Check if -no-pie works.
+AC_CACHE_CHECK([for -no-pie option],
+  [gcc_cv_no_pie],
+  [saved_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -no-pie"
+   AC_LINK_IFELSE([int main(void) {return 0;}],
+ [gcc_cv_no_pie=yes],
+ [gcc_cv_no_pie=no])
+   LDFLAGS="$saved_LDFLAGS"])
+if test "$gcc_cv_no_pie" = "yes"; then
+  NO_PIE_FLAG="-no-pie"
+fi
+AC_SUBST([NO_PIE_FLAG])

will check if CXX supports -no-pic and set NO_PIE_FLAG accordingly.
The gcc/Makefile.in fragment:

@@ -761,6 +769,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS)

 # Native linker and preprocessor flags.  For x-fragment overrides.
 BUILD_LDFLAGS=@BUILD_LDFLAGS@
+BUILD_LDFLAGS += @NO_PIE_FLAG@

constructs the flags which will ultimately be used to compile the
build machines gen* programs.  That compilation uses CXX_FOR_BUILD
with the NO_PIE_FLAG that was originally probed for CXX.  This is
incorrect if CXX_FOR_BUILD != CXX

HJ, could you take a look into this issue?

Thanks
/Marcus


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-10-23 Thread H.J. Lu
On Fri, Oct 23, 2015 at 4:54 AM, Marcus Shawcroft
 wrote:
> Hi,
>
> This patch breaks the distinction between build and host. For example
> consider a configure along these lines:
>
> ./configure --host=aarch64-none-linux-gnu
> --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu
>
> Will result in:
>
> CXX_FOR_BUILD='g++'
> CXX='aarch64-none-linux-gnu-g++'
>
> the gcc/configure fragment:
>
> +# Check if -no-pie works.
> +AC_CACHE_CHECK([for -no-pie option],
> +  [gcc_cv_no_pie],
> +  [saved_LDFLAGS="$LDFLAGS"
> +   LDFLAGS="$LDFLAGS -no-pie"
> +   AC_LINK_IFELSE([int main(void) {return 0;}],
> + [gcc_cv_no_pie=yes],
> + [gcc_cv_no_pie=no])
> +   LDFLAGS="$saved_LDFLAGS"])
> +if test "$gcc_cv_no_pie" = "yes"; then
> +  NO_PIE_FLAG="-no-pie"
> +fi
> +AC_SUBST([NO_PIE_FLAG])
>
> will check if CXX supports -no-pic and set NO_PIE_FLAG accordingly.
> The gcc/Makefile.in fragment:
>
> @@ -761,6 +769,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS)
>
>  # Native linker and preprocessor flags.  For x-fragment overrides.
>  BUILD_LDFLAGS=@BUILD_LDFLAGS@
> +BUILD_LDFLAGS += @NO_PIE_FLAG@
>
> constructs the flags which will ultimately be used to compile the
> build machines gen* programs.  That compilation uses CXX_FOR_BUILD
> with the NO_PIE_FLAG that was originally probed for CXX.  This is
> incorrect if CXX_FOR_BUILD != CXX
>
> HJ, could you take a look into this issue?
>

Try this.

-- 
H.J.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index b91b8dc..d9d2de9 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -258,11 +258,14 @@ LINKER = $(CC)
 LINKER_FLAGS = $(CFLAGS)
 endif
 
+NO_PIE_CFLAG = @NO_PIE_CFLAGS@
+NO_PIE_FLAG = @NO_PIE_FLAG@
+
 # We don't want to compile the compilers with -fPIE, it make PCH fail.
-COMPILER += @NO_PIE_CFLAGS@
+COMPILER += $(NO_PIE_CFLAG)
 
 # Link with -no-pie since we compile the compiler with -fno-PIE.
-LINKER += @NO_PIE_FLAG@
+LINKER += $(NO_PIE_FLAG)
 
 # Like LINKER, but use a mutex for serializing front end links.
 ifeq (@DO_LINK_MUTEX@,true)
@@ -755,10 +758,13 @@ DIR = ../gcc
 # Native compiler for the build machine and its switches.
 CC_FOR_BUILD = @CC_FOR_BUILD@
 CXX_FOR_BUILD = @CXX_FOR_BUILD@
+NO_PIE_CFLAGS_FOR_BUILD = @NO_PIE_CFLAGS_FOR_BUILD@
+NO_PIE_FLAG_FOR_BUILD = @NO_PIE_FLAG_FOR_BUILD@
 BUILD_CFLAGS= @BUILD_CFLAGS@ -DGENERATOR_FILE
 BUILD_CXXFLAGS = @BUILD_CXXFLAGS@ -DGENERATOR_FILE
-BUILD_CFLAGS += @NO_PIE_CFLAGS@
-BUILD_CXXFLAGS += @NO_PIE_CFLAGS@
+BUILD_NO_PIE_CFLAGS = @BUILD_NO_PIE_CFLAGS@
+BUILD_CFLAGS += $(BUILD_NO_PIE_CFLAGS)
+BUILD_CXXFLAGS += $(BUILD_NO_PIE_CFLAGS)
 
 # Native compiler that we use.  This may be C++ some day.
 COMPILER_FOR_BUILD = $(CXX_FOR_BUILD)
@@ -770,7 +776,8 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS)
 
 # Native linker and preprocessor flags.  For x-fragment overrides.
 BUILD_LDFLAGS=@BUILD_LDFLAGS@
-BUILD_LDFLAGS += @NO_PIE_FLAG@
+BUILD_NO_PIE_FLAG = @BUILD_NO_PIE_FLAG@
+BUILD_LDFLAGS += $(BUILD_NO_PIE_FLAG)
 BUILD_CPPFLAGS= -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \
 		-I$(srcdir)/../include @INCINTL@ $(CPPINC) $(CPPFLAGS)
 
diff --git a/gcc/configure b/gcc/configure
index 3122499..92bda6c 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -707,6 +707,10 @@ FGREP
 SED
 LIBTOOL
 collect2
+NO_PIE_FLAG_FOR_BUILD
+NO_PIE_CFLAGS_FOR_BUILD
+BUILD_NO_PIE_FLAG
+BUILD_NO_PIE_CFLAGS
 STMP_FIXINC
 BUILD_LDFLAGS
 BUILD_CXXFLAGS
@@ -7096,7 +7100,8 @@ if test x$ac_checking != x ; then
 
 $as_echo "#define ENABLE_CHECKING 1" >>confdefs.h
 
-  $as_echo "#define CHECKING_P 1" >>confdefs.h
+
+$as_echo "#define CHECKING_P 1" >>confdefs.h
 
   nocommon_flag=-fno-common
 else
@@ -12253,14 +12258,24 @@ BUILD_CXXFLAGS='$(ALL_CXXFLAGS)'
 BUILD_LDFLAGS='$(LDFLAGS)'
 STMP_FIXINC=stmp-fixinc
 
+BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS)'
+BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG)'
+
 # And these apply if build != host, or we are generating coverage data
 if test x$build != x$host || test "x$coverage_flags" != x
 then
 BUILD_CFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CFLAGS_FOR_BUILD)'
 BUILD_CXXFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CXXFLAGS_FOR_BUILD)'
 BUILD_LDFLAGS='$(LDFLAGS_FOR_BUILD)'
+
+NO_PIE_CFLAGS_FOR_BUILD=${NO_PIE_CFLAGS_FOR_BUILD-${NO_PIE_CFLAGS}}
+NO_PIE_FLAG_FOR_BUILD=${NO_PIE_FLAG_FOR_BUILD-${NO_PIE_FLAG}}
+BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS_FOR_BUILD)'
+BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG_FOR_BUILD)'
 fi
 
+
+
 # Expand extra_headers to include complete path.
 # This substitutes for lots of t-* files.
 extra_headers_list=
@@ -18390,7 +18405,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18393 "configure"
+#line 18408 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18496,7 +18511,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18499 "configure"
+#line 18514 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure

Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-10-23 Thread Marcus Shawcroft
On 23 October 2015 at 13:34, H.J. Lu  wrote:
> On Fri, Oct 23, 2015 at 4:54 AM, Marcus Shawcroft
>  wrote:
>> Hi,
>>
>> This patch breaks the distinction between build and host. For example
>> consider a configure along these lines:
>>
>> ./configure --host=aarch64-none-linux-gnu
>> --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu

>> HJ, could you take a look into this issue?
>>
>
> Try this.

Thanks HJ. This solves the issue I was seeing.

Cheers
/Marcus


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-10-28 Thread Marcus Shawcroft
On 23 October 2015 at 13:34, H.J. Lu  wrote:
> On Fri, Oct 23, 2015 at 4:54 AM, Marcus Shawcroft
>  wrote:
>> Hi,
>>
>> This patch breaks the distinction between build and host. For example
>> consider a configure along these lines:
>>
>> ./configure --host=aarch64-none-linux-gnu
>> --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu
>> HJ, could you take a look into this issue?
>>
>
> Try this.

Hi,  Can we get a review from one of the build machinery maintainers
for this patch?

Cheers
/Marcus


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-10-29 Thread Richard Earnshaw
On 23/10/15 13:34, H.J. Lu wrote:
> On Fri, Oct 23, 2015 at 4:54 AM, Marcus Shawcroft
>  wrote:
>> Hi,
>>
>> This patch breaks the distinction between build and host. For example
>> consider a configure along these lines:
>>
>> ./configure --host=aarch64-none-linux-gnu
>> --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu
>>
>> Will result in:
>>
>> CXX_FOR_BUILD='g++'
>> CXX='aarch64-none-linux-gnu-g++'
>>
>> the gcc/configure fragment:
>>
>> +# Check if -no-pie works.
>> +AC_CACHE_CHECK([for -no-pie option],
>> +  [gcc_cv_no_pie],
>> +  [saved_LDFLAGS="$LDFLAGS"
>> +   LDFLAGS="$LDFLAGS -no-pie"
>> +   AC_LINK_IFELSE([int main(void) {return 0;}],
>> + [gcc_cv_no_pie=yes],
>> + [gcc_cv_no_pie=no])
>> +   LDFLAGS="$saved_LDFLAGS"])
>> +if test "$gcc_cv_no_pie" = "yes"; then
>> +  NO_PIE_FLAG="-no-pie"
>> +fi
>> +AC_SUBST([NO_PIE_FLAG])
>>
>> will check if CXX supports -no-pic and set NO_PIE_FLAG accordingly.
>> The gcc/Makefile.in fragment:
>>
>> @@ -761,6 +769,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS)
>>
>>  # Native linker and preprocessor flags.  For x-fragment overrides.
>>  BUILD_LDFLAGS=@BUILD_LDFLAGS@
>> +BUILD_LDFLAGS += @NO_PIE_FLAG@
>>
>> constructs the flags which will ultimately be used to compile the
>> build machines gen* programs.  That compilation uses CXX_FOR_BUILD
>> with the NO_PIE_FLAG that was originally probed for CXX.  This is
>> incorrect if CXX_FOR_BUILD != CXX
>>
>> HJ, could you take a look into this issue?
>>
> 
> Try this.
> 

Where's the ChangeLog?

R.

> 
> pie.patch
> 
> 
> diff --git a/gcc/Makefile.in b/gcc/Makefile.in
> index b91b8dc..d9d2de9 100644
> --- a/gcc/Makefile.in
> +++ b/gcc/Makefile.in
> @@ -258,11 +258,14 @@ LINKER = $(CC)
>  LINKER_FLAGS = $(CFLAGS)
>  endif
>  
> +NO_PIE_CFLAG = @NO_PIE_CFLAGS@
> +NO_PIE_FLAG = @NO_PIE_FLAG@
> +
>  # We don't want to compile the compilers with -fPIE, it make PCH fail.
> -COMPILER += @NO_PIE_CFLAGS@
> +COMPILER += $(NO_PIE_CFLAG)
>  
>  # Link with -no-pie since we compile the compiler with -fno-PIE.
> -LINKER += @NO_PIE_FLAG@
> +LINKER += $(NO_PIE_FLAG)
>  
>  # Like LINKER, but use a mutex for serializing front end links.
>  ifeq (@DO_LINK_MUTEX@,true)
> @@ -755,10 +758,13 @@ DIR = ../gcc
>  # Native compiler for the build machine and its switches.
>  CC_FOR_BUILD = @CC_FOR_BUILD@
>  CXX_FOR_BUILD = @CXX_FOR_BUILD@
> +NO_PIE_CFLAGS_FOR_BUILD = @NO_PIE_CFLAGS_FOR_BUILD@
> +NO_PIE_FLAG_FOR_BUILD = @NO_PIE_FLAG_FOR_BUILD@
>  BUILD_CFLAGS= @BUILD_CFLAGS@ -DGENERATOR_FILE
>  BUILD_CXXFLAGS = @BUILD_CXXFLAGS@ -DGENERATOR_FILE
> -BUILD_CFLAGS += @NO_PIE_CFLAGS@
> -BUILD_CXXFLAGS += @NO_PIE_CFLAGS@
> +BUILD_NO_PIE_CFLAGS = @BUILD_NO_PIE_CFLAGS@
> +BUILD_CFLAGS += $(BUILD_NO_PIE_CFLAGS)
> +BUILD_CXXFLAGS += $(BUILD_NO_PIE_CFLAGS)
>  
>  # Native compiler that we use.  This may be C++ some day.
>  COMPILER_FOR_BUILD = $(CXX_FOR_BUILD)
> @@ -770,7 +776,8 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS)
>  
>  # Native linker and preprocessor flags.  For x-fragment overrides.
>  BUILD_LDFLAGS=@BUILD_LDFLAGS@
> -BUILD_LDFLAGS += @NO_PIE_FLAG@
> +BUILD_NO_PIE_FLAG = @BUILD_NO_PIE_FLAG@
> +BUILD_LDFLAGS += $(BUILD_NO_PIE_FLAG)
>  BUILD_CPPFLAGS= -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \
>   -I$(srcdir)/../include @INCINTL@ $(CPPINC) $(CPPFLAGS)
>  
> diff --git a/gcc/configure b/gcc/configure
> index 3122499..92bda6c 100755
> --- a/gcc/configure
> +++ b/gcc/configure
> @@ -707,6 +707,10 @@ FGREP
>  SED
>  LIBTOOL
>  collect2
> +NO_PIE_FLAG_FOR_BUILD
> +NO_PIE_CFLAGS_FOR_BUILD
> +BUILD_NO_PIE_FLAG
> +BUILD_NO_PIE_CFLAGS
>  STMP_FIXINC
>  BUILD_LDFLAGS
>  BUILD_CXXFLAGS
> @@ -7096,7 +7100,8 @@ if test x$ac_checking != x ; then
>  
>  $as_echo "#define ENABLE_CHECKING 1" >>confdefs.h
>  
> -  $as_echo "#define CHECKING_P 1" >>confdefs.h
> +
> +$as_echo "#define CHECKING_P 1" >>confdefs.h
>  
>nocommon_flag=-fno-common
>  else
> @@ -12253,14 +12258,24 @@ BUILD_CXXFLAGS='$(ALL_CXXFLAGS)'
>  BUILD_LDFLAGS='$(LDFLAGS)'
>  STMP_FIXINC=stmp-fixinc
>  
> +BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS)'
> +BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG)'
> +
>  # And these apply if build != host, or we are generating coverage data
>  if test x$build != x$host || test "x$coverage_flags" != x
>  then
>  BUILD_CFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CFLAGS_FOR_BUILD)'
>  BUILD_CXXFLAGS='$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CXXFLAGS_FOR_BUILD)'
>  BUILD_LDFLAGS='$(LDFLAGS_FOR_BUILD)'
> +
> +NO_PIE_CFLAGS_FOR_BUILD=${NO_PIE_CFLAGS_FOR_BUILD-${NO_PIE_CFLAGS}}
> +NO_PIE_FLAG_FOR_BUILD=${NO_PIE_FLAG_FOR_BUILD-${NO_PIE_FLAG}}
> +BUILD_NO_PIE_CFLAGS='$(NO_PIE_CFLAGS_FOR_BUILD)'
> +BUILD_NO_PIE_FLAG='$(NO_PIE_FLAG_FOR_BUILD)'
>  fi
>  
> +
> +
>  # Expand extra_headers to include complete path.
>  # This substitutes for lots of t-* files.
>  extra_headers_list=
> @@ -18390,7 +18405,7 @@ else
>lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>lt_status=$lt_dlunknown
>cat > conftest.$ac_ext <<_LT_EOF
> -#line 18393 "c

Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-10-29 Thread H.J. Lu
On Thu, Oct 29, 2015 at 4:00 AM, Richard Earnshaw
 wrote:
> On 23/10/15 13:34, H.J. Lu wrote:
>> On Fri, Oct 23, 2015 at 4:54 AM, Marcus Shawcroft
>>  wrote:
>>> Hi,
>>>
>>> This patch breaks the distinction between build and host. For example
>>> consider a configure along these lines:
>>>
>>> ./configure --host=aarch64-none-linux-gnu
>>> --target=aarch64-none-linux-gnu --build=x86_64-pc-linux-gnu
>>>
>>> Will result in:
>>>
>>> CXX_FOR_BUILD='g++'
>>> CXX='aarch64-none-linux-gnu-g++'
>>>
>>> the gcc/configure fragment:
>>>
>>> +# Check if -no-pie works.
>>> +AC_CACHE_CHECK([for -no-pie option],
>>> +  [gcc_cv_no_pie],
>>> +  [saved_LDFLAGS="$LDFLAGS"
>>> +   LDFLAGS="$LDFLAGS -no-pie"
>>> +   AC_LINK_IFELSE([int main(void) {return 0;}],
>>> + [gcc_cv_no_pie=yes],
>>> + [gcc_cv_no_pie=no])
>>> +   LDFLAGS="$saved_LDFLAGS"])
>>> +if test "$gcc_cv_no_pie" = "yes"; then
>>> +  NO_PIE_FLAG="-no-pie"
>>> +fi
>>> +AC_SUBST([NO_PIE_FLAG])
>>>
>>> will check if CXX supports -no-pic and set NO_PIE_FLAG accordingly.
>>> The gcc/Makefile.in fragment:
>>>
>>> @@ -761,6 +769,7 @@ BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS)
>>>
>>>  # Native linker and preprocessor flags.  For x-fragment overrides.
>>>  BUILD_LDFLAGS=@BUILD_LDFLAGS@
>>> +BUILD_LDFLAGS += @NO_PIE_FLAG@
>>>
>>> constructs the flags which will ultimately be used to compile the
>>> build machines gen* programs.  That compilation uses CXX_FOR_BUILD
>>> with the NO_PIE_FLAG that was originally probed for CXX.  This is
>>> incorrect if CXX_FOR_BUILD != CXX
>>>
>>> HJ, could you take a look into this issue?
>>>
>>
>> Try this.
>>
>
> Where's the ChangeLog?
>

You can follow up here:

https://gcc.gnu.org/ml/gcc-patches/2015-10/msg02468.html

-- 
H.J.


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-30 Thread Andreas Schwab
"H.J. Lu"  writes:

> +# Check if -fno-PIE works.
> +AC_CACHE_CHECK([for -fno-PIE option],
> +  [gcc_cv_c_no_fpie],
> +  [saved_CFLAGS="$CFLAGS"
> +   CFLAGS="$CFLAGS -fno-PIE"
> +   AC_COMPILE_IFELSE([int main(void) {return 0;}],
> + [gcc_cv_c_no_fpie=yes],
> + [gcc_cv_c_no_fpie=no])
> +   CFLAGS="$saved_CFLAGS"])
> +if test "$gcc_cv_c_no_fpie" = "yes"; then
> +  NO_PIE_CFLAGS="-fno-PIE"
> +fi
> +AC_SUBST([NO_PIE_CFLAGS])
> +

That doesn't work:

configure:28726: checking for -fno-PIE option
configure:28737: g++ -c -g   conftest.cpp >&5
configure:28737: $? = 0
configure:28745: result: yes

> +# Check if -no-pie works.
> +AC_CACHE_CHECK([for -no-pie option],
> +  [gcc_cv_no_pie],
> +  [saved_LDFLAGS="$LDFLAGS"
> +   LDFLAGS="$LDFLAGS -no-pie"
> +   AC_LINK_IFELSE([int main(void) {return 0;}],
> + [gcc_cv_no_pie=yes],
> + [gcc_cv_no_pie=no])
> +   LDFLAGS="$saved_LDFLAGS"])
> +if test "$gcc_cv_no_pie" = "yes"; then
> +  NO_PIE_FLAG="-no-pie"
> +fi
> +AC_SUBST([NO_PIE_FLAG])
> +

That doesn't work with gcc 4.3:

configure:28753: checking for -no-pie option
configure:28764: g++ -std=c++98 -o conftest -g -no-pie conftest.cpp  >&5
g++: unrecognized option '-no-pie'
configure:28764: $? = 0
configure:28773: result: yes

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-30 Thread H.J. Lu
On Sat, May 30, 2015 at 8:10 AM, Andreas Schwab  wrote:
> "H.J. Lu"  writes:
>
>> +# Check if -fno-PIE works.
>> +AC_CACHE_CHECK([for -fno-PIE option],
>> +  [gcc_cv_c_no_fpie],
>> +  [saved_CFLAGS="$CFLAGS"
>> +   CFLAGS="$CFLAGS -fno-PIE"
>> +   AC_COMPILE_IFELSE([int main(void) {return 0;}],
>> + [gcc_cv_c_no_fpie=yes],
>> + [gcc_cv_c_no_fpie=no])
>> +   CFLAGS="$saved_CFLAGS"])
>> +if test "$gcc_cv_c_no_fpie" = "yes"; then
>> +  NO_PIE_CFLAGS="-fno-PIE"
>> +fi
>> +AC_SUBST([NO_PIE_CFLAGS])
>> +
>
> That doesn't work:
>
> configure:28726: checking for -fno-PIE option
> configure:28737: g++ -c -g   conftest.cpp >&5
> configure:28737: $? = 0
> configure:28745: result: yes
>
>> +# Check if -no-pie works.
>> +AC_CACHE_CHECK([for -no-pie option],
>> +  [gcc_cv_no_pie],
>> +  [saved_LDFLAGS="$LDFLAGS"
>> +   LDFLAGS="$LDFLAGS -no-pie"
>> +   AC_LINK_IFELSE([int main(void) {return 0;}],
>> + [gcc_cv_no_pie=yes],
>> + [gcc_cv_no_pie=no])
>> +   LDFLAGS="$saved_LDFLAGS"])
>> +if test "$gcc_cv_no_pie" = "yes"; then
>> +  NO_PIE_FLAG="-no-pie"
>> +fi
>> +AC_SUBST([NO_PIE_FLAG])
>> +
>
> That doesn't work with gcc 4.3:
>
> configure:28753: checking for -no-pie option
> configure:28764: g++ -std=c++98 -o conftest -g -no-pie conftest.cpp  >&5
> g++: unrecognized option '-no-pie'
> configure:28764: $? = 0
> configure:28773: result: yes
>

Starting GCC 4.6, the unrecognized option became an error.
Before 4.6, it was ignored.  Does it cause any problems for
bootstrap?

-- 
H.J.


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-30 Thread Andreas Schwab
"H.J. Lu"  writes:

> Starting GCC 4.6, the unrecognized option became an error.
> Before 4.6, it was ignored.  Does it cause any problems for
> bootstrap?

No, only spurious messages.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-30 Thread H.J. Lu
On Sat, May 30, 2015 at 8:54 AM, Andreas Schwab  wrote:
> "H.J. Lu"  writes:
>
>> Starting GCC 4.6, the unrecognized option became an error.
>> Before 4.6, it was ignored.  Does it cause any problems for
>> bootstrap?
>
> No, only spurious messages.
>

There is no harm and the message is gone in stage 2 and 3,
We can treat it the same as other spurious messages from the
bootstrap compiler.


-- 
H.J.


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-30 Thread Andreas Schwab
"H.J. Lu"  writes:

> diff --git a/gcc/config/m68k/m68k.h b/gcc/config/m68k/m68k.h
> index 88356cc..74ebff7 100644
> --- a/gcc/config/m68k/m68k.h
> +++ b/gcc/config/m68k/m68k.h
> @@ -40,7 +40,8 @@ along with GCC; see the file COPYING3.  If not see
>  %{m68020-40:-m68040}%{m68020-60:-m68040}\
>  %{mcpu=*:-mcpu=%*}%{march=*:-march=%*}\
>  "
> -#define ASM_PCREL_SPEC "%{fPIC|fpic|mpcrel:--pcrel} \
> +#define ASM_PCREL_SPEC "%{" FPIC_SPEC ":--pcrel} \
> + %{mpcrel:%{" NO_FPIC_SPEC ":--pcrel}} \
>   %{msep-data|mid-shared-library:--pcrel} \

That expands to a spurious --pcrel with -fno-PIE, causing the assembler
to error out while compiling crtstuff if the compiler is configured with
--enable-default-pie.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-30 Thread Andreas Schwab
"H.J. Lu"  writes:

> There is no harm and the message is gone in stage 2 and 3,
> We can treat it the same as other spurious messages from the
> bootstrap compiler.

But you still need to fix the first test, since it doesn't test
anything.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-30 Thread Andreas Schwab
Andreas Schwab  writes:

> "H.J. Lu"  writes:
>
>> diff --git a/gcc/config/m68k/m68k.h b/gcc/config/m68k/m68k.h
>> index 88356cc..74ebff7 100644
>> --- a/gcc/config/m68k/m68k.h
>> +++ b/gcc/config/m68k/m68k.h
>> @@ -40,7 +40,8 @@ along with GCC; see the file COPYING3.  If not see
>>  %{m68020-40:-m68040}%{m68020-60:-m68040}\
>>  %{mcpu=*:-mcpu=%*}%{march=*:-march=%*}\
>>  "
>> -#define ASM_PCREL_SPEC "%{fPIC|fpic|mpcrel:--pcrel} \
>> +#define ASM_PCREL_SPEC "%{" FPIC_SPEC ":--pcrel} \
>> + %{mpcrel:%{" NO_FPIC_SPEC ":--pcrel}} \
>>   %{msep-data|mid-shared-library:--pcrel} \
>
> That expands to a spurious --pcrel with -fno-PIE, causing the assembler
> to error out while compiling crtstuff if the compiler is configured with
> --enable-default-pie.

This was already buggy before, -fpie should always have implied --pcrel.
Fixed as below.

Andreas.

* config/m68k/m68k.h (ASM_PCREL_SPEC): Pass --pcrel also for
implict or explicit -fPIE or -fpie.

diff --git a/gcc/config/m68k/m68k.h b/gcc/config/m68k/m68k.h
index 74ebff7..b227c67 100644
--- a/gcc/config/m68k/m68k.h
+++ b/gcc/config/m68k/m68k.h
@@ -40,8 +40,8 @@ along with GCC; see the file COPYING3.  If not see
 %{m68020-40:-m68040}%{m68020-60:-m68040}\
 %{mcpu=*:-mcpu=%*}%{march=*:-march=%*}\
 "
-#define ASM_PCREL_SPEC "%{" FPIC_SPEC ":--pcrel} \
- %{mpcrel:%{" NO_FPIC_SPEC ":--pcrel}} \
+#define ASM_PCREL_SPEC "%{" FPIE_OR_FPIC_SPEC ":--pcrel} \
+ %{mpcrel:%{" NO_FPIE_AND_FPIC_SPEC ":--pcrel}} \
  %{msep-data|mid-shared-library:--pcrel} \
 "
 
-- 
2.4.2

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-30 Thread H.J. Lu
On Sat, May 30, 2015 at 9:44 AM, Andreas Schwab  wrote:
> "H.J. Lu"  writes:
>
>> There is no harm and the message is gone in stage 2 and 3,
>> We can treat it the same as other spurious messages from the
>> bootstrap compiler.
>
> But you still need to fix the first test, since it doesn't test
> anything.
>

What is wrong with it?  Its purpose is to always compile GCC
without PIE.  If the bootstrap compiler allows -fno-PIE, we add
it.  Does the test pass when the bootstrap compiler errors
on -fno-PIE?


-- 
H.J.


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-30 Thread Andreas Schwab
"H.J. Lu"  writes:

> What is wrong with it?

It tests nothing.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-30 Thread H.J. Lu
On Sat, May 30, 2015 at 2:18 PM, Andreas Schwab  wrote:
> "H.J. Lu"  writes:
>
>> What is wrong with it?
>
> It tests nothing.
>

Can you explain?

-- 
H.J.


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-31 Thread Andreas Schwab
configure:28726: checking for -fno-PIE option
configure:28737: g++ -c -g   conftest.cpp >&5
configure:28737: $? = 0
configure:28745: result: yes

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-31 Thread H.J. Lu
On Sun, May 31, 2015 at 12:04 AM, Andreas Schwab  wrote:
> configure:28726: checking for -fno-PIE option
> configure:28737: g++ -c -g   conftest.cpp >&5
> configure:28737: $? = 0
> configure:28745: result: yes

Since GCC is written in C++ now, we need to check CXXFLAGS instead of CFLAGS
for NO_PIE_CFLAGS.  I checked it in as an obvious fix.

Thanks.

-- 
H.J.
---
Index: ChangeLog
===
--- ChangeLog (revision 223898)
+++ ChangeLog (working copy)
@@ -1,3 +1,8 @@
+2015-05-31  H.J. Lu  
+
+ * configure.ac (NO_PIE_CFLAGS): Check CXXFLAGS instead of CFLAGS.
+ * configure: Regenerated.
+
 2015-05-31  Mikhail Maltsev  

  * config/cris/cris.h (CRIS_ARCH_CPP_DEFAULT): Fix C++11 compatibility
Index: configure
===
--- configure (revision 223898)
+++ configure (working copy)
@@ -28728,8 +28728,8 @@ $as_echo_n "checking for -fno-PIE option
 if test "${gcc_cv_c_no_fpie+set}" = set; then :
   $as_echo_n "(cached) " >&6
 else
-  saved_CFLAGS="$CFLAGS"
-   CFLAGS="$CFLAGS -fno-PIE"
+  saved_CXXFLAGS="$CXXFLAGS"
+   CXXFLAGS="$CXXFLAGS -fno-PIE"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 int main(void) {return 0;}
@@ -28740,7 +28740,7 @@ else
   gcc_cv_c_no_fpie=no
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-   CFLAGS="$saved_CFLAGS"
+   CXXFLAGS="$saved_CXXFLAGS"
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_c_no_fpie" >&5
 $as_echo "$gcc_cv_c_no_fpie" >&6; }
Index: configure.ac
===
--- configure.ac (revision 223898)
+++ configure.ac (working copy)
@@ -5834,12 +5834,12 @@ AC_SUBST([enable_default_pie])
 # Check if -fno-PIE works.
 AC_CACHE_CHECK([for -fno-PIE option],
   [gcc_cv_c_no_fpie],
-  [saved_CFLAGS="$CFLAGS"
-   CFLAGS="$CFLAGS -fno-PIE"
+  [saved_CXXFLAGS="$CXXFLAGS"
+   CXXFLAGS="$CXXFLAGS -fno-PIE"
AC_COMPILE_IFELSE([int main(void) {return 0;}],
  [gcc_cv_c_no_fpie=yes],
  [gcc_cv_c_no_fpie=no])
-   CFLAGS="$saved_CFLAGS"])
+   CXXFLAGS="$saved_CXXFLAGS"])
 if test "$gcc_cv_c_no_fpie" = "yes"; then
   NO_PIE_CFLAGS="-fno-PIE"
 fi


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-22 Thread H.J. Lu
I fixed a typo in gcc/config/openbsd.h.  Here is the updated patch.  The whole
patch is also on hjl/pie/master branch in GCC git mirror.

-- 
H.J.
From 64364101d6c888e20eb1146ee2baac4b08e684cf Mon Sep 17 00:00:00 2001
From: "H.J. Lu" 
Date: Tue, 19 May 2015 10:12:20 -0700
Subject: [PATCH] Add --enable-default-pie option to GCC configure

Add --enable-default-pie option to configure GCC to generate PIE by
default.

gcc/

2015-05-19  Magnus Granberg  
	H.J. Lu  

	* Makefile.in (COMPILER): Add @NO_PIE_CFLAGS@.
	(BUILD_CFLAGS): Likewise.
	(BUILD_CXXFLAGS): Likewise.
	(LINKER): Add @NO_PIE_FLAG@.
	(BUILD_LDFLAGS): Likewise.
	(libgcc.mvars): Set NO_PIE_CFLAGS to -fno-PIE for
	--enable-default-pie.
	* common.opt (fPIE): Initialize to -1.
	(fpie): Likewise.
	(no-pie): New option.
	(pie): Replace "Negative(shared)" with "Negative(no-pie)".
	* configure.ac: Add --enable-default-pie.
	(NO_PIE_CFLAGS): New.  Check if -fno-PIE works.  AC_SUBST.
	(NO_PIE_FLAG): New.  Check if -no-pie works.  AC_SUBST.
	* defaults.h (DEFAULT_FLAG_PIE): New.  Default PIE to -fPIE.
	* gcc.c (NO_PIE_SPEC): New.
	(PIE_SPEC): Likewise.
	(NO_FPIE1_SPEC): Likewise.
	(FPIE1_SPEC): Likewise.
	(NO_FPIE2_SPEC): Likewise.
	(FPIE2_SPEC): Likewise.
	(NO_FPIE2_SPEC): Likewise.
	(FPIE_SPEC): Likewise.
	(NO_FPIE_SPEC): Likewise.
	(NO_FPIC1_SPEC): Likewise.
	(FPIC1_SPEC): Likewise.
	(NO_FPIC2_SPEC): Likewise.
	(FPIC2_SPEC): Likewise.
	(NO_FPIC2_SPEC): Likewise.
	(FPIC_SPEC): Likewise.
	(NO_FPIC_SPEC): Likewise.
	(NO_FPIE1_AND_FPIC1_SPEC): Likewise.
	(FPIE1_OR_FPIC1_SPEC): Likewise.
	(NO_FPIE2_AND_FPIC2_SPEC): Likewise.
	(FPIE2_OR_FPIC2_SPEC): Likewise.
	(NO_FPIE_AND_FPIC_SPEC): Likewise.
	(FPIE_OR_FPIC_SPEC): Likewise.
	(LD_PIE_SPEC): Likewise.
	(LINK_PIE_SPEC): Handle -no-pie.  Use PIE_SPEC and LD_PIE_SPEC.
	* opts.c (finish_options): Update opts->x_flag_pie if it is -1.
	* config/darwin.h (PIE_SPEC): Renamed to ...
	(DARWIN_PIE_SPEC): This.
	(LINK_SPEC): Replace PIE_SPEC with DARWIN_PIE_SPEC.
	* config/darwin9.h (PIE_SPEC): Renamed to ...
	(DARWIN_PIE_SPEC): This.
	* config/gnu-user.h (GNU_USER_TARGET_STARTFILE_SPEC): Use
	PIE_SPEC and NO_PIE_SPEC if HAVE_LD_PIE is defined.
	* config/openbsd.h (ASM_SPEC): Use FPIE1_OR_FPIC1_SPEC and
	FPIE2_OR_FPIC2_SPEC.
	* config/m68k/netbsd-elf.h (ASM_SPEC): Likewise.
	* config/m68k/openbsd.h (ASM_SPEC): Likewise.
	* gcc/config/sol2.h (ASM_PIC_SPEC): Likewise.
	* config/arm/freebsd.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
	* config/arm/netbsd-elf.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
	* config/arm/semi.h (SUBTARGET_EXTRA_ASM_SPEC): Likewise.
	* config/cris/linux.h (CRIS_ASM_SUBTARGET_SPEC): Likewise.
	* config/m32r/m32r.h (ASM_SPEC): Likewise.
	* config/m68k/uclinux.h (DRIVER_SELF_SPECS): Likewise.
	* config/rs6000/linux64.h (ASM_SPEC32): Likewise.
	* config/rs6000/sysv4.h (ASM_SPEC): Likewise.
	* config/sparc/freebsd.h (ASM_SPEC): Likewise.
	* config/sparc/linux.h (ASM_SPEC): Likewise.
	* config/sparc/linux64.h (ASM_SPEC): Likewise.
	* config/sparc/netbsd-elf.h (ASM_SPEC): Likewise.
	* config/sparc/openbsd64.h (ASM_SPEC): Likewise.
	* config/sparc/sp-elf.h (ASM_SPEC): Likewise.
	* config/sparc/sp64-elf.h (ASM_SPEC): Likewise.
	* config/sparc/sparc.h (ASM_SPEC): Likewise.
	* config/sparc/sysv4.h (ASM_SPEC): Likewise.
	* config/sparc/vxworks.h (ASM_SPEC): Likewise.
	* config/c6x/elf-common.h (ASM_SPEC): Use NO_FPIC2_SPEC,
	FPIC2_SPEC, FPIC1_SPEC and FPIC2_SPEC.
	* config/c6x/uclinux-elf.h (LINK_SPEC): Use FPIE_SPEC.
	* config/frv/frv.h (DRIVER_SELF_SPECS): Use FPIC_SPEC,
	NO_FPIC_SPEC and NO_FPIE1_AND_FPIC1_SPEC.
	(ASM_SPEC): Use FPIE1_OR_FPIC1_SPEC and FPIE2_OR_FPIC2_SPEC.
	* config/m68k/m68k.h (ASM_PCREL_SPEC): Use FPIC_SPEC and
	NO_FPIC_SPEC.
	* config/mips/gnu-user.h (NO_SHARED_SPECS): Use
	NO_FPIE_AND_FPIC_SPEC.
	* config/mips/vxworks.h (SUBTARGET_ASM_SPEC): Use FPIC_SPEC.
	* config/rs6000/freebsd64.h (ASM_SPEC32): Likewise.
	* config/rs6000/vxworks.h (ASM_SPEC): Likewise.
	* config/vax/linux.h (ASM_SPEC): Likewise.
	* doc/install.texi: Document --enable-default-pie.
	* doc/invoke.texi: Document -no-pie.
	* config.in: Regenerated.
	* configure: Likewise.

gcc/ada/

2015-05-19  H.J. Lu  

	* gcc-interface/Makefile.in (TOOLS_LIBS): Add @NO_PIE_FLAG@.

libgcc/

2015-05-19  H.J. Lu  

	* Makefile.in (CRTSTUFF_CFLAGS): Add $(NO_PIE_CFLAGS).
---
 gcc/Makefile.in   | 15 
 gcc/ada/gcc-interface/Makefile.in |  3 ++
 gcc/common.opt| 10 +++--
 gcc/config.in |  6 +++
 gcc/config/arm/freebsd.h  |  2 +-
 gcc/config/arm/netbsd-elf.h   |  2 +-
 gcc/config/arm/semi.h |  2 +-
 gcc/config/c6x/elf-common.h   |  6 ++-
 gcc/config/c6x/uclinux-elf.h  |  2 +-
 gcc/config/cris/linux.h   |  4 +-
 gcc/config/darwin.h   |  4 +-
 gcc/config/darwin9.h  |  4 +-
 gcc/config/frv/frv.h  | 10 ++---
 gcc/config/gnu-user.h |  7 +++-
 gcc/config/m32r/m32r.h|  2 +-
 gcc/config/m68k/m68

Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-26 Thread Bill Schmidt
Hi H.J.,

I tried your patch on powerpc64le-linux-gnu, and it fails to bootstrap
as follows:

> g++ -std=c++98 -c   -g -DIN_GCC-fno-exceptions -fno-rtti 
> -fasynchronous-unwi
> nd-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format 
> -Wmiss
> ing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long 
> -Wno-variadic
> -macros -Wno-overlength-strings -fno-common  -DHAVE_CONFIG_H -DGENERATOR_FILE 
> @N
> O_PIE_CFLAGS@ -I. -Ibuild -I/home/wschmidt/gcc/gcc-mainline-test/gcc 
> -I/home/wsc
> hmidt/gcc/gcc-mainline-test/gcc/build 
> -I/home/wschmidt/gcc/gcc-mainline-test/gcc
> /../include  -I/home/wschmidt/gcc/gcc-mainline-test/gcc/../libcpp/include  \
> -DBASEVER="\"6.0.0\"" -DDATESTAMP="\" 20150526\"" \
> -DREVISION="\" [trunk revision 223719]\"" \
> -DDEVPHASE="\" (experimental)\"" -DPKGVERSION="\"(GCC) \"" \
> -DBUGURL="\"\"" -o build/version.o 
> /home/wschmidt/gcc/gcc-mainline-test/gcc/version.c
> g++: error: @NO_PIE_CFLAGS@: No such file or directory
> make[3]: *** [build/version.o] Error 1

Thanks,
Bill

On Fri, 2015-05-22 at 08:18 -0700, H.J. Lu wrote:
> I fixed a typo in gcc/config/openbsd.h.  Here is the updated patch.  The whole
> patch is also on hjl/pie/master branch in GCC git mirror.
> 




Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-26 Thread Bill Schmidt
Ah, never mind.  I guess I need to run automake first.

Bill

On Tue, 2015-05-26 at 16:39 -0500, Bill Schmidt wrote:
> Hi H.J.,
> 
> I tried your patch on powerpc64le-linux-gnu, and it fails to bootstrap
> as follows:
> 
> > g++ -std=c++98 -c   -g -DIN_GCC-fno-exceptions -fno-rtti 
> > -fasynchronous-unwi
> > nd-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format 
> > -Wmiss
> > ing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long 
> > -Wno-variadic
> > -macros -Wno-overlength-strings -fno-common  -DHAVE_CONFIG_H 
> > -DGENERATOR_FILE @N
> > O_PIE_CFLAGS@ -I. -Ibuild -I/home/wschmidt/gcc/gcc-mainline-test/gcc 
> > -I/home/wsc
> > hmidt/gcc/gcc-mainline-test/gcc/build 
> > -I/home/wschmidt/gcc/gcc-mainline-test/gcc
> > /../include  -I/home/wschmidt/gcc/gcc-mainline-test/gcc/../libcpp/include  \
> > -DBASEVER="\"6.0.0\"" -DDATESTAMP="\" 20150526\"" \
> > -DREVISION="\" [trunk revision 223719]\"" \
> > -DDEVPHASE="\" (experimental)\"" -DPKGVERSION="\"(GCC) \"" \
> > -DBUGURL="\"\"" -o build/version.o 
> > /home/wschmidt/gcc/gcc-mainline-test/gcc/version.c
> > g++: error: @NO_PIE_CFLAGS@: No such file or directory
> > make[3]: *** [build/version.o] Error 1
> 
> Thanks,
> Bill
> 
> On Fri, 2015-05-22 at 08:18 -0700, H.J. Lu wrote:
> > I fixed a typo in gcc/config/openbsd.h.  Here is the updated patch.  The 
> > whole
> > patch is also on hjl/pie/master branch in GCC git mirror.
> > 
> 




Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-27 Thread Peter Bergner
On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote:
> Ah, never mind.  I guess I need to run automake first.

I ran the patch on powerpc64-linux (ie, Big Endian) both with and
without --enable-default-pie.  Both bootstraps completed with no
errors and the without --enable-default-pie regtested without any
regressions.

The --enable-default-pie regtesting shows massive failures that I
have to look into.  I'm haven't determined yet whether these are
all -m32 FAILs or -m64 FAILS or both.  I'll report back with more
info after I dig into some of the failures.

Peter





Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-27 Thread H.J. Lu
On Wed, May 27, 2015 at 8:24 AM, Peter Bergner  wrote:
> On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote:
>> Ah, never mind.  I guess I need to run automake first.
>
> I ran the patch on powerpc64-linux (ie, Big Endian) both with and
> without --enable-default-pie.  Both bootstraps completed with no
> errors and the without --enable-default-pie regtested without any
> regressions.
>
> The --enable-default-pie regtesting shows massive failures that I
> have to look into.  I'm haven't determined yet whether these are
> all -m32 FAILs or -m64 FAILS or both.  I'll report back with more
> info after I dig into some of the failures.

Does --enable-default-pie work on powerpc64-linux?  Do you
get working PIE by default?  Some GCC tests expect non-PIE.
I fixed some of them:

commit 82923064d660e4183933b014ee3f645799a945b0
Author: hjl 
Date:   Thu Jan 15 16:33:37 2015 +

Ignore additional linker messages on Linux/x86 with PIE

g++.dg/other/anon5.C is expected to fail to link.  On Linux/x86 with PIE
and the new linker, there are additional messages from linker:

[hjl@gnu-tools-1 gcc]$ g++  -fPIE -pie
/export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/other/anon5.C
/tmp/ccwg53fj.o: In function `f()': anon5.C:(.text+0x7): undefined
reference to `(anonymous namespace)::c::t'
/usr/local/bin/ld: /tmp/ccwg53fj.o: relocation R_X86_64_PC32
against undefined symbol `_ZN12_GLOBAL__N_11c1tE' can not be used when
making a shared object; recompile with -fPIC
/usr/local/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
[hjl@gnu-tools-1 gcc]$

This patch ignores additional linker messages on Linux/x86 with PIE.

  * g++.dg/other/anon5.C: Ignore additional messages on Linux/x86
  with PIE.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219667
138bc75d-0d04-0410-961f-82ee72b054a4


-- 
H.J.


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-27 Thread Peter Bergner
On Wed, 2015-05-27 at 08:36 -0700, H.J. Lu wrote:
> On Wed, May 27, 2015 at 8:24 AM, Peter Bergner  wrote:
> > On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote:
> >> Ah, never mind.  I guess I need to run automake first.
> >
> > I ran the patch on powerpc64-linux (ie, Big Endian) both with and
> > without --enable-default-pie.  Both bootstraps completed with no
> > errors and the without --enable-default-pie regtested without any
> > regressions.
> >
> > The --enable-default-pie regtesting shows massive failures that I
> > have to look into.  I'm haven't determined yet whether these are
> > all -m32 FAILs or -m64 FAILS or both.  I'll report back with more
> > info after I dig into some of the failures.
> 
> Does --enable-default-pie work on powerpc64-linux?  Do you
> get working PIE by default?  Some GCC tests expect non-PIE.
> I fixed some of them:

I haven't looked into any of the failures yet.  That said,
powerpc64-linux is PIC by default, so I thought maybe PIE
would just work.  Maybe it does and it's just powerpc-linux
tests that are failing (I run the testsuite with both
-m32 and -m64).  I won't know until I get some time to have
a deeper look.  That said, if there is something you know
of that I should look for or at, I'd appreciate it.

Peter




Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-27 Thread H.J. Lu
On Wed, May 27, 2015 at 9:05 AM, Peter Bergner  wrote:
> On Wed, 2015-05-27 at 08:36 -0700, H.J. Lu wrote:
>> On Wed, May 27, 2015 at 8:24 AM, Peter Bergner  wrote:
>> > On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote:
>> >> Ah, never mind.  I guess I need to run automake first.
>> >
>> > I ran the patch on powerpc64-linux (ie, Big Endian) both with and
>> > without --enable-default-pie.  Both bootstraps completed with no
>> > errors and the without --enable-default-pie regtested without any
>> > regressions.
>> >
>> > The --enable-default-pie regtesting shows massive failures that I
>> > have to look into.  I'm haven't determined yet whether these are
>> > all -m32 FAILs or -m64 FAILS or both.  I'll report back with more
>> > info after I dig into some of the failures.
>>
>> Does --enable-default-pie work on powerpc64-linux?  Do you
>> get working PIE by default?  Some GCC tests expect non-PIE.
>> I fixed some of them:
>
> I haven't looked into any of the failures yet.  That said,
> powerpc64-linux is PIC by default, so I thought maybe PIE

PIC != PIE.  Is PIE the default for powerpc64-linux? Please
show me

# readelf -h /bin/ls

on powerpc64-linux.

> would just work.  Maybe it does and it's just powerpc-linux
> tests that are failing (I run the testsuite with both
> -m32 and -m64).  I won't know until I get some time to have
> a deeper look.  That said, if there is something you know
> of that I should look for or at, I'd appreciate it.
>

You should first verify if --enable-default-pie generates a GCC which
can produce a simple hello program.

-- 
H.J.


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-27 Thread David Edelsohn
On Wed, May 27, 2015 at 12:18 PM, H.J. Lu  wrote:
> On Wed, May 27, 2015 at 9:05 AM, Peter Bergner  wrote:
>> On Wed, 2015-05-27 at 08:36 -0700, H.J. Lu wrote:
>>> On Wed, May 27, 2015 at 8:24 AM, Peter Bergner  wrote:
>>> > On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote:
>>> >> Ah, never mind.  I guess I need to run automake first.
>>> >
>>> > I ran the patch on powerpc64-linux (ie, Big Endian) both with and
>>> > without --enable-default-pie.  Both bootstraps completed with no
>>> > errors and the without --enable-default-pie regtested without any
>>> > regressions.
>>> >
>>> > The --enable-default-pie regtesting shows massive failures that I
>>> > have to look into.  I'm haven't determined yet whether these are
>>> > all -m32 FAILs or -m64 FAILS or both.  I'll report back with more
>>> > info after I dig into some of the failures.
>>>
>>> Does --enable-default-pie work on powerpc64-linux?  Do you
>>> get working PIE by default?  Some GCC tests expect non-PIE.
>>> I fixed some of them:
>>
>> I haven't looked into any of the failures yet.  That said,
>> powerpc64-linux is PIC by default, so I thought maybe PIE
>
> PIC != PIE.  Is PIE the default for powerpc64-linux? Please
> show me
>
> # readelf -h /bin/ls
>
> on powerpc64-linux.
>
>> would just work.  Maybe it does and it's just powerpc-linux
>> tests that are failing (I run the testsuite with both
>> -m32 and -m64).  I won't know until I get some time to have
>> a deeper look.  That said, if there is something you know
>> of that I should look for or at, I'd appreciate it.
>>
>
> You should first verify if --enable-default-pie generates a GCC which
> can produce a simple hello program.

The --enable-default-pie patch itself works correctly -- as intended
-- for powerpc64-linux and powerpc64le-linux and the rs6000 parts of
the patch are okay with me.  In other words, the option is fine but is
not enabled by default so it will not cause any problems.

Debugging the testsuite failures is a separate issue.

Thanks, David


Re: Fwd: PING^3: [PATCH]: New configure options that make the compiler use -fPIE and -pie as default option

2015-05-27 Thread H.J. Lu
On Wed, May 27, 2015 at 9:59 AM, David Edelsohn  wrote:
> On Wed, May 27, 2015 at 12:18 PM, H.J. Lu  wrote:
>> On Wed, May 27, 2015 at 9:05 AM, Peter Bergner  wrote:
>>> On Wed, 2015-05-27 at 08:36 -0700, H.J. Lu wrote:
 On Wed, May 27, 2015 at 8:24 AM, Peter Bergner  
 wrote:
 > On Tue, 2015-05-26 at 16:40 -0500, Bill Schmidt wrote:
 >> Ah, never mind.  I guess I need to run automake first.
 >
 > I ran the patch on powerpc64-linux (ie, Big Endian) both with and
 > without --enable-default-pie.  Both bootstraps completed with no
 > errors and the without --enable-default-pie regtested without any
 > regressions.
 >
 > The --enable-default-pie regtesting shows massive failures that I
 > have to look into.  I'm haven't determined yet whether these are
 > all -m32 FAILs or -m64 FAILS or both.  I'll report back with more
 > info after I dig into some of the failures.

 Does --enable-default-pie work on powerpc64-linux?  Do you
 get working PIE by default?  Some GCC tests expect non-PIE.
 I fixed some of them:
>>>
>>> I haven't looked into any of the failures yet.  That said,
>>> powerpc64-linux is PIC by default, so I thought maybe PIE
>>
>> PIC != PIE.  Is PIE the default for powerpc64-linux? Please
>> show me
>>
>> # readelf -h /bin/ls
>>
>> on powerpc64-linux.
>>
>>> would just work.  Maybe it does and it's just powerpc-linux
>>> tests that are failing (I run the testsuite with both
>>> -m32 and -m64).  I won't know until I get some time to have
>>> a deeper look.  That said, if there is something you know
>>> of that I should look for or at, I'd appreciate it.
>>>
>>
>> You should first verify if --enable-default-pie generates a GCC which
>> can produce a simple hello program.
>
> The --enable-default-pie patch itself works correctly -- as intended
> -- for powerpc64-linux and powerpc64le-linux and the rs6000 parts of
> the patch are okay with me.  In other words, the option is fine but is
> not enabled by default so it will not cause any problems.

Good to know.

> Debugging the testsuite failures is a separate issue.

Thanks.

-- 
H.J.