diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2023-01-09 14:36:39 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2023-01-09 14:36:39 +0000 |
commit | b5310815f7dec27fcf60bcde1f952aa19d1e76cb (patch) | |
tree | bfa3f31bed7c50cf3b774425d20eff4a56697ee8 /gnu | |
parent | 9471a72e0f46240f7aecf4fb66974648b6e36c8a (diff) |
Implement --execute-only (and turn --no-execute-only from a no-op into an
options that does the opposite).
Note that this option is likely to be ineffective without changes to the
linker scripts. A change that adjusts the hppa linker scripts will follow
shortly. Other architectures will need some work.
ok deraadt@
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/usr.bin/binutils-2.17/bfd/elf.c | 3 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/include/bfdlink.h | 3 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/ld/lexsup.c | 14 |
3 files changed, 17 insertions, 3 deletions
diff --git a/gnu/usr.bin/binutils-2.17/bfd/elf.c b/gnu/usr.bin/binutils-2.17/bfd/elf.c index 2d2ed030eca..a2804f5a068 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/elf.c +++ b/gnu/usr.bin/binutils-2.17/bfd/elf.c @@ -4597,7 +4597,8 @@ assign_file_positions_for_segments (bfd *abfd, struct bfd_link_info *link_info) if (! m->p_flags_valid) { - p->p_flags |= PF_R; + if ((flags & SEC_CODE) == 0 || !link_info->execute_only) + p->p_flags |= PF_R; if ((flags & SEC_CODE) != 0) p->p_flags |= PF_X; if ((flags & SEC_READONLY) == 0) diff --git a/gnu/usr.bin/binutils-2.17/include/bfdlink.h b/gnu/usr.bin/binutils-2.17/include/bfdlink.h index e419f77f625..8c17bf888bc 100644 --- a/gnu/usr.bin/binutils-2.17/include/bfdlink.h +++ b/gnu/usr.bin/binutils-2.17/include/bfdlink.h @@ -265,6 +265,9 @@ struct bfd_link_info unsigned int allow_multiple_definition: 1; /* TRUE if output program should be marked to request W^X permission */ + unsigned int execute_only: 1; + + /* TRUE if output program should be marked to request W^X permission */ unsigned int wxneeded: 1; /* TRUE if ok to have version with no definition. */ diff --git a/gnu/usr.bin/binutils-2.17/ld/lexsup.c b/gnu/usr.bin/binutils-2.17/ld/lexsup.c index ab1da63cb96..2e3a6e901fb 100644 --- a/gnu/usr.bin/binutils-2.17/ld/lexsup.c +++ b/gnu/usr.bin/binutils-2.17/ld/lexsup.c @@ -77,6 +77,8 @@ enum option_values OPTION_EL, OPTION_EMBEDDED_RELOCS, OPTION_EXPORT_DYNAMIC, + OPTION_EXECUTE_ONLY, + OPTION_NO_EXECUTE_ONLY, OPTION_HELP, OPTION_IGNORE, OPTION_MAP, @@ -361,6 +363,10 @@ static const struct ld_option ld_options[] = TWO_DASHES }, { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS}, '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES}, + { {"execute-only", no_argument, NULL, OPTION_EXECUTE_ONLY}, + '\0', NULL, N_("Mark executable sections unreadable"), TWO_DASHES}, + { {"no-execute-only", no_argument, NULL, OPTION_NO_EXECUTE_ONLY}, + '\0', NULL, N_("Do not mark executable sections unreadable"), TWO_DASHES}, { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}, '\0', NULL, N_("Treat warnings as errors"), TWO_DASHES }, @@ -525,8 +531,6 @@ static const struct ld_option ld_options[] = TWO_DASHES }, { {"wrap", required_argument, NULL, OPTION_WRAP}, '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES }, - { {"no-execute-only", no_argument, NULL, OPTION_IGNORE}, - '\0', NULL, N_("Ignored for lld compatibility"), TWO_DASHES}, }; #define OPTION_COUNT ARRAY_SIZE (ld_options) @@ -771,6 +775,12 @@ parse_args (unsigned argc, char **argv) case OPTION_EMBEDDED_RELOCS: command_line.embedded_relocs = TRUE; break; + case OPTION_EXECUTE_ONLY: + link_info.execute_only = TRUE; + break; + case OPTION_NO_EXECUTE_ONLY: + link_info.execute_only = FALSE; + break; case OPTION_EXPORT_DYNAMIC: case 'E': /* HP/UX compatibility. */ link_info.export_dynamic = TRUE; |