Re: [PATCH] gcc: Use ld -r when checking for HAVE_LD_RO_RW_SECTION_MIXING

2022-12-05 Thread Joakim Nohlgård
On Mon, Nov 28, 2022 at 5:53 PM Jeff Law  wrote:
>
>
> On 11/28/22 06:59, Joakim Nohlgård wrote:
> > The check for HAVE_LD_RO_RW_SECTION_MIXING fails on targets where ld
> > does not support shared objects, even though the answer to the test
> > should be 'read-write'. One such target is riscv64-unknown-elf. Failing
> > this test results in a libgcc crtbegin.o which has a writable .eh_frame
> > section leading to the default linker scripts placing the .eh_frame
> > section in a writable memory segment, or a linker warning about writable
> > sections in a read-only segment when using ld scripts that place
> > .eh_frame unconditionally in ROM.
> >
> > gcc/ChangeLog:
> >
> >   * configure: Regenerate.
> >   * configure.ac: Use ld -r in the check for 
> > HAVE_LD_RO_RW_SECTION_MIXING
>
> I'm not sure that simply replacing -shared with -r is the right fix
> here.  ISTM that if the -shared tests fails, then we can/should try the
> -r variant.Am I missing something here?
>
I have posted a v2 patch. The new patch tries ld -shared first and
falling back to ld -r if that fails.

I believe the original reason for using ld -shared in the first place
was that it was a convenient way to let the conftest1,2,3 code be as
simple as possible. Using ld without any flags would require a program
entry point (_start) at the very minimum. Using ld -r has the same
effect as the ld -shared link in this case, where we just want to
merge sections with the same name from different input files and check
what section flags were propagated to the output file.


[PATCH v2] gcc: Use ld -r when checking for HAVE_LD_RO_RW_SECTION_MIXING

2022-12-05 Thread Joakim Nohlgård
Fall back to ld -r if ld -shared fails during configure. The check for
HAVE_LD_RO_RW_SECTION_MIXING can fail on targets where ld does not
support shared objects, even though the answer to the test should be
'read-write'. One such target is riscv64-unknown-elf. Failing this test
results in a libgcc crtbegin.o which has a writable .eh_frame section
leading to the default linker scripts placing the .eh_frame section in a
writable memory segment, or a linker warning when using ld scripts that
place .eh_frame unconditionally in ROM.

gcc/ChangeLog:

* configure: Regenerate.
* configure.ac: Use ld -r in the check for HAVE_LD_RO_RW_SECTION_MIXING

Signed-off-by: Joakim Nohlgård 
---
 gcc/configure.ac | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/gcc/configure.ac b/gcc/configure.ac
index 7c55bff6cb0..500829ceb1d 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -3152,16 +3152,19 @@ elif test x$gcc_cv_as != x -a x$gcc_cv_ld != x -a 
x$gcc_cv_objdump != x ; then
   echo '.byte 0' >> conftest3.s
   if $gcc_cv_as -o conftest1.o conftest1.s > /dev/null 2>&1 \
  && $gcc_cv_as -o conftest2.o conftest2.s > /dev/null 2>&1 \
- && $gcc_cv_as -o conftest3.o conftest3.s > /dev/null 2>&1 \
- && $gcc_cv_ld -shared -o conftest1.so conftest1.o \
-   conftest2.o conftest3.o > /dev/null 2>&1; then
-gcc_cv_ld_ro_rw_mix=`$gcc_cv_objdump -h conftest1.so \
-| sed -e '/myfoosect/!d' -e N`
-if echo "$gcc_cv_ld_ro_rw_mix" | grep CONTENTS > /dev/null; then
-  if echo "$gcc_cv_ld_ro_rw_mix" | grep READONLY > /dev/null; then
-   gcc_cv_ld_ro_rw_mix=read-only
-  else
-   gcc_cv_ld_ro_rw_mix=read-write
+ && $gcc_cv_as -o conftest3.o conftest3.s > /dev/null 2>&1; then
+if $gcc_cv_ld -shared -o conftest1.so conftest1.o \
+   conftest2.o conftest3.o > /dev/null 2>&1 \
+   || $gcc_cv_ld -r -o conftest1.so conftest1.o \
+ conftest2.o conftest3.o > /dev/null 2>&1; then
+  gcc_cv_ld_ro_rw_mix=`$gcc_cv_objdump -h conftest1.so \
+  | sed -e '/myfoosect/!d' -e N`
+  if echo "$gcc_cv_ld_ro_rw_mix" | grep CONTENTS > /dev/null; then
+   if echo "$gcc_cv_ld_ro_rw_mix" | grep READONLY > /dev/null; then
+ gcc_cv_ld_ro_rw_mix=read-only
+   else
+ gcc_cv_ld_ro_rw_mix=read-write
+   fi
   fi
 fi
   fi
-- 
2.38.1



[PATCH] c++: Fall back to global cpp spec if CPLUSPLUS_CPP_SPEC is not defined

2022-11-28 Thread Joakim Nohlgård
When CPLUSPLUS_CPP_SPEC is set to a string literal it is not possible to
modify it through external spec files by renaming the original cpp spec
and replacing it because the compiler cpp_spec will still point to the
original, renamed cpp spec. Not defining CPLUSPLUS_CPP_SPEC makes gcc.cc
fall back to using the same cpp spec as the C compiler when substituting
%C in spec strings.

gcc/ChangeLog:

* defaults.h (CPLUSPLUS_CPP_SPEC): Remove default definition.

Signed-off-by: Joakim Nohlgård 
---
 gcc/defaults.h | 8 
 1 file changed, 8 deletions(-)

diff --git a/gcc/defaults.h b/gcc/defaults.h
index 376687d91b1..223460ef239 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -783,14 +783,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
 #endif
 #endif
 
-/* By default, the preprocessor should be invoked the same way in C++
-   as in C.  */
-#ifndef CPLUSPLUS_CPP_SPEC
-#ifdef CPP_SPEC
-#define CPLUSPLUS_CPP_SPEC CPP_SPEC
-#endif
-#endif
-
 #ifndef ACCUMULATE_OUTGOING_ARGS
 #define ACCUMULATE_OUTGOING_ARGS 0
 #endif
-- 
2.38.1



[PATCH] gcc: Use ld -r when checking for HAVE_LD_RO_RW_SECTION_MIXING

2022-11-28 Thread Joakim Nohlgård
The check for HAVE_LD_RO_RW_SECTION_MIXING fails on targets where ld
does not support shared objects, even though the answer to the test
should be 'read-write'. One such target is riscv64-unknown-elf. Failing
this test results in a libgcc crtbegin.o which has a writable .eh_frame
section leading to the default linker scripts placing the .eh_frame
section in a writable memory segment, or a linker warning about writable
sections in a read-only segment when using ld scripts that place
.eh_frame unconditionally in ROM.

gcc/ChangeLog:

* configure: Regenerate.
* configure.ac: Use ld -r in the check for HAVE_LD_RO_RW_SECTION_MIXING

Signed-off-by: Joakim Nohlgård 
---
 gcc/configure.ac | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/configure.ac b/gcc/configure.ac
index 7c55bff6cb0..4f36ed4aff3 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -3153,9 +3153,9 @@ elif test x$gcc_cv_as != x -a x$gcc_cv_ld != x -a 
x$gcc_cv_objdump != x ; then
   if $gcc_cv_as -o conftest1.o conftest1.s > /dev/null 2>&1 \
  && $gcc_cv_as -o conftest2.o conftest2.s > /dev/null 2>&1 \
  && $gcc_cv_as -o conftest3.o conftest3.s > /dev/null 2>&1 \
- && $gcc_cv_ld -shared -o conftest1.so conftest1.o \
+ && $gcc_cv_ld -r -o conftest.o conftest1.o \
conftest2.o conftest3.o > /dev/null 2>&1; then
-gcc_cv_ld_ro_rw_mix=`$gcc_cv_objdump -h conftest1.so \
+gcc_cv_ld_ro_rw_mix=`$gcc_cv_objdump -h conftest.o \
 | sed -e '/myfoosect/!d' -e N`
 if echo "$gcc_cv_ld_ro_rw_mix" | grep CONTENTS > /dev/null; then
   if echo "$gcc_cv_ld_ro_rw_mix" | grep READONLY > /dev/null; then
-- 
2.38.1