hardened: use LD_PIE_SPEC only if defined

Message ID orwmtg36na.fsf@lxoliva.fsfla.org
State Unresolved
Headers
Series hardened: use LD_PIE_SPEC only if defined |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Alexandre Oliva Dec. 14, 2023, 7:50 p.m. UTC
  sol2.h may define LINK_PIE_SPEC and leave LD_PIE_SPEC undefined, but
gcc.cc will only provide a LD_PIE_SPEC definition if LINK_PIE_SPEC is
not defined, and then it uses LD_PIE_SPEC guarded by #ifdef HAVE_LD_PIE
only.  Add LD_PIE_SPEC to the guard.

Regstrapped on x86_64-linux-gnu; also testing on sparc-solaris2.11.3,
where I hit the problem and couldn't build a baseline to compare with.
Ok to install?


gcc/ChangeLog

	* gcc.cc (process_command): Use LD_PIE_SPEC only if defined.
---
 gcc/gcc.cc |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Marek Polacek Dec. 14, 2023, 8:06 p.m. UTC | #1
On Thu, Dec 14, 2023 at 04:50:49PM -0300, Alexandre Oliva wrote:
> 
> sol2.h may define LINK_PIE_SPEC and leave LD_PIE_SPEC undefined, but
> gcc.cc will only provide a LD_PIE_SPEC definition if LINK_PIE_SPEC is
> not defined, and then it uses LD_PIE_SPEC guarded by #ifdef HAVE_LD_PIE
> only.  Add LD_PIE_SPEC to the guard.
> 
> Regstrapped on x86_64-linux-gnu; also testing on sparc-solaris2.11.3,
> where I hit the problem and couldn't build a baseline to compare with.
> Ok to install?
 
OK, thanks.  Jakub notified me of this problem a few days ago and
I forgot about it, sorry :(.
 
> gcc/ChangeLog
> 
> 	* gcc.cc (process_command): Use LD_PIE_SPEC only if defined.
> ---
>  gcc/gcc.cc |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gcc/gcc.cc b/gcc/gcc.cc
> index 701f5cdfb59c8..d5e02c11cb05d 100644
> --- a/gcc/gcc.cc
> +++ b/gcc/gcc.cc
> @@ -5008,7 +5008,7 @@ process_command (unsigned int decoded_options_count,
>      {
>        if (!any_link_options_p && !static_p)
>  	{
> -#ifdef HAVE_LD_PIE
> +#if defined HAVE_LD_PIE && defined LD_PIE_SPEC
>  	  save_switch (LD_PIE_SPEC, 0, NULL, /*validated=*/true, /*known=*/false);
>  #endif
>  	  /* These are passed straight down to collect2 so we have to break
> 
> -- 
> Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
>    Free Software Activist                   GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive
> 

Marek
  

Patch

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 701f5cdfb59c8..d5e02c11cb05d 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -5008,7 +5008,7 @@  process_command (unsigned int decoded_options_count,
     {
       if (!any_link_options_p && !static_p)
 	{
-#ifdef HAVE_LD_PIE
+#if defined HAVE_LD_PIE && defined LD_PIE_SPEC
 	  save_switch (LD_PIE_SPEC, 0, NULL, /*validated=*/true, /*known=*/false);
 #endif
 	  /* These are passed straight down to collect2 so we have to break