Skip to content

Commit 8478900

Browse files
committed
ppc32 and "LOAD segment with RWX permissions"
When using a bss-plt we'll always trigger the RWX warning, which disturbs gcc test results. On the other hand, there may be reason to want the warning when gcc is configured with --enable-secureplt. So turning off the warning entirely for powerpc might not be the best solution. Instead, we'll turn off the warning whenever a bss-plt is generated, unless the user explicitly asked for the warning. bfd/ * elf32-ppc.c (ppc_elf_select_plt_layout): Set no_warn_rwx_segments on generating a bss plt, unless explicity enabled by the user. Also show the bss-plt warning when --warn-rwx-segments is given without --bss-plt. include/ * bfdlink.h (struct bfd_link_info): Add user_warn_rwx_segments. ld/ * lexsup.c (parse_args): Set user_warn_rwx_segments. * testsuite/ld-elf/elf.exp: Pass --secure-plt for powerpc to the rwx tests.
1 parent 9af467b commit 8478900

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

bfd/elf32-ppc.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4020,12 +4020,19 @@ ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
40204020
htab->plt_type = plt_type;
40214021
}
40224022
}
4023-
if (htab->plt_type == PLT_OLD && htab->params->plt_style == PLT_NEW)
4023+
if (htab->plt_type == PLT_OLD)
40244024
{
4025-
if (htab->old_bfd != NULL)
4026-
_bfd_error_handler (_("bss-plt forced due to %pB"), htab->old_bfd);
4027-
else
4028-
_bfd_error_handler (_("bss-plt forced by profiling"));
4025+
if (!info->user_warn_rwx_segments)
4026+
info->no_warn_rwx_segments = 1;
4027+
if (htab->params->plt_style == PLT_NEW
4028+
|| (htab->params->plt_style != PLT_OLD
4029+
&& !info->no_warn_rwx_segments))
4030+
{
4031+
if (htab->old_bfd != NULL)
4032+
_bfd_error_handler (_("bss-plt forced due to %pB"), htab->old_bfd);
4033+
else
4034+
_bfd_error_handler (_("bss-plt forced by profiling"));
4035+
}
40294036
}
40304037

40314038
BFD_ASSERT (htab->plt_type != PLT_VXWORKS);

include/bfdlink.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ struct bfd_link_info
501501
/* TRUE if warnings should not be generated for TLS segments with eXecute
502502
permission or LOAD segments with RWX permissions. */
503503
unsigned int no_warn_rwx_segments: 1;
504+
/* TRUE if the user gave either --warn-rwx-segments or
505+
--no-warn-rwx-segments. */
506+
unsigned int user_warn_rwx_segments: 1;
504507

505508
/* TRUE if the stack can be made executable because of the absence of a
506509
.note.GNU-stack section in an input file. Note - even if this field

ld/lexsup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,11 @@ parse_args (unsigned argc, char **argv)
936936
break;
937937
case OPTION_WARN_RWX_SEGMENTS:
938938
link_info.no_warn_rwx_segments = 0;
939+
link_info.user_warn_rwx_segments = 1;
939940
break;
940941
case OPTION_NO_WARN_RWX_SEGMENTS:
941942
link_info.no_warn_rwx_segments = 1;
943+
link_info.user_warn_rwx_segments = 1;
942944
break;
943945
case 'e':
944946
lang_add_entry (optarg, true);

ld/testsuite/ld-elf/elf.exp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ if { [istarget *-*-*linux*]
238238
return $text
239239
}
240240

241+
set curr_ldflags $LDFLAGS
242+
if { [istarget powerpc*-*-*] && ![istarget powerpc64*-*-*] } {
243+
# Don't generate an executable .plt section
244+
set LDFLAGS "$LDFLAGS --secure-plt"
245+
}
246+
241247
# Since the warnings can be disabled by configure, ensure consistency
242248
# of the first test by forcing the flags.
243249
run_ld_link_tests [list \
@@ -285,6 +291,8 @@ if { [istarget *-*-*linux*]
285291
"rwx-segments-3.exe"] \
286292
]
287293

294+
set LDFLAGS $curr_ldflags
295+
288296
if { [target_defaults_to_execstack] } {
289297
run_ld_link_tests [list \
290298
[list "PR ld/29072 (warn about absent .note.GNU-stack)" \

0 commit comments

Comments
 (0)