Skip to content

Commit

Permalink
Uniformise the .note.GNU-stack section output
Browse files Browse the repository at this point in the history
Uniformly rely on the detection during `configure` of whether the
`.note.GNU-stack` section is supported to decide whether to output it

- On x86_64:
  - it was generated by `emit.mlp` only on Linux and FreeBSD
  - it was present in `amd64.S` only on Linux and FreeBSD
- On ARM:
  - it was generated by `emit.mlp` only on Linux
  - it was present in `arm64.S` except on macOS
- On RISC-V:
  - it was never generated by `emit.mlp`
  - it was always present in `riscv.S`
- On POWER:
  - it was always generated by `emit.mlp`
  - it was always present in `power.S`
- on S/390:
  - it was always generated by `emit.mlp`
  - it was always present in `s390x.S`
  • Loading branch information
shym committed Jan 15, 2025
1 parent cea82e7 commit e0621f0
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion asmcomp/amd64/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ let end_assembly() =
D.size frametable (ConstSub (ConstThis, ConstLabel frametable))
end;

if system = S_linux || system = S_freebsd then
if Config.linker_support_note_gnu_stack_noexec then
(* Mark stack as non-executable, PR#4564 *)
D.section [".note.GNU-stack"] (Some "") [ "%progbits" ];

Expand Down
8 changes: 3 additions & 5 deletions asmcomp/arm64/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,9 +1224,7 @@ let end_assembly () =
efa_string = (fun s -> emit_string_directive " .asciz " s) };
emit_symbol_type emit_symbol lbl "object";
emit_symbol_size lbl;
begin match Config.system with
| "linux" ->
(* Mark stack as non-executable *)
` .section .note.GNU-stack,\"\",%progbits\n`
| _ -> ()
if Config.linker_support_note_gnu_stack_noexec then begin
(* Mark stack as non-executable *)
` .section .note.GNU-stack,\"\",%progbits\n`
end
5 changes: 4 additions & 1 deletion asmcomp/power/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,4 +1170,7 @@ let end_assembly() =
emit_string toc_space;
emit_toctable();
Hashtbl.clear tocref_entries;
` .section .note.GNU-stack,\"\",%progbits\n`
if Config.linker_support_note_gnu_stack_noexec then begin
(* Mark stack as non-executable *)
` .section .note.GNU-stack,\"\",%progbits\n`
end
6 changes: 5 additions & 1 deletion asmcomp/riscv/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,8 @@ let end_assembly() =
` .long ({emit_label lbl} - .) + {emit_int32 ofs}\n`);
efa_def_label = (fun l -> `{emit_label l}:\n`);
efa_string = (fun s -> emit_bytes_directive " .byte " (s ^ "\000"))
}
};
if Config.linker_support_note_gnu_stack_noexec then begin
(* Mark stack as non-executable *)
` .section .note.GNU-stack,\"\",%progbits\n`
end
6 changes: 4 additions & 2 deletions asmcomp/s390x/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -865,5 +865,7 @@ let end_assembly() =
efa_def_label = (fun l -> `{emit_label l}:\n`);
efa_string = (fun s -> emit_bytes_directive " .byte " (s ^ "\000"))
};
(* Mark stack as non-executable *)
` .section .note.GNU-stack,\"\",%progbits\n`
if Config.linker_support_note_gnu_stack_noexec then begin
(* Mark stack as non-executable *)
` .section .note.GNU-stack,\"\",%progbits\n`
end
2 changes: 1 addition & 1 deletion runtime/amd64.S
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ G(caml_negf_mask):
G(caml_absf_mask):
.quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF

#if defined(SYS_linux) || defined(SYS_freebsd)
#ifdef SUPPORT_NOTE_GNU_STACK_NOEXEC
/* Mark stack as non-executable, PR#4564 */
.section .note.GNU-stack,"",%progbits
#endif
2 changes: 1 addition & 1 deletion runtime/arm64.S
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ OBJECT(caml_system$frametable)
.align 3
END_OBJECT(caml_system$frametable)

#if !defined(SYS_macosx)
#ifdef SUPPORT_NOTE_GNU_STACK_NOEXEC
/* Mark stack as non-executable */
.section .note.GNU-stack,"",%progbits
#endif
2 changes: 2 additions & 0 deletions runtime/power.S
Original file line number Diff line number Diff line change
Expand Up @@ -1223,5 +1223,7 @@ TOCENTRY(caml_array_bound_error_asm)
TOCENTRYLABEL(fiber_exn_handler)
TOCENTRYLABEL(trap_handler)

#ifdef SUPPORT_NOTE_GNU_STACK_NOEXEC
/* Mark stack as non-executable */
.section .note.GNU-stack,"",%progbits
#endif
3 changes: 3 additions & 0 deletions runtime/riscv.S
Original file line number Diff line number Diff line change
Expand Up @@ -1258,5 +1258,8 @@ OBJECT(caml_system$frametable)
.short 0 /* no roots */
.align 3
END_OBJECT(caml_system$frametable)

#ifdef SUPPORT_NOTE_GNU_STACK_NOEXEC
/* Mark stack as non-executable */
.section .note.GNU-stack,"",%progbits
#endif
2 changes: 2 additions & 0 deletions runtime/s390x.S
Original file line number Diff line number Diff line change
Expand Up @@ -1217,5 +1217,7 @@ OBJECT(caml_system$frametable)
.align 8
ENDOBJECT(caml_system$frametable)

#ifdef SUPPORT_NOTE_GNU_STACK_NOEXEC
/* Mark stack as non-executable */
.section .note.GNU-stack,"",%progbits
#endif
4 changes: 4 additions & 0 deletions testsuite/tools/asmgen_arm.S
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
/* */
/**************************************************************************/

#include "caml/m.h"

.text

.global call_gen_code
Expand All @@ -38,5 +40,7 @@ caml_c_call:
@ function to call is in r10
bx r10

#ifdef SUPPORT_NOTE_GNU_STACK_NOEXEC
/* Mark stack as non-executable */
.section .note.GNU-stack,"",%progbits
#endif
4 changes: 3 additions & 1 deletion testsuite/tools/asmgen_arm64.S
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
/* */
/**************************************************************************/

#include "caml/m.h"

#if defined(SYS_macosx)
#define G(sym) _##sym
#else
Expand Down Expand Up @@ -60,7 +62,7 @@ G(call_gen_code):
G(caml_c_call):
br x15

#if !defined(SYS_macosx)
#ifdef SUPPORT_NOTE_GNU_STACK_NOEXEC
/* Mark stack as non-executable */
.section .note.GNU-stack,"",%progbits
#endif
4 changes: 4 additions & 0 deletions testsuite/tools/asmgen_power.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
/* */
/*********************************************************************/

#include "caml/m.h"

#define RESERVED_STACK 32
#define LR_SAVE_AREA 16

Expand Down Expand Up @@ -131,5 +133,7 @@ FUNCTION(caml_c_call)
mr 12, 28
bctr

#ifdef SUPPORT_NOTE_GNU_STACK_NOEXEC
/* Mark stack as non-executable */
.section .note.GNU-stack,"",%progbits
#endif
4 changes: 4 additions & 0 deletions testsuite/tools/asmgen_s390x.S
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "caml/m.h"

#define ALIGN 8

#define CALL_GEN_CODE call_gen_code
Expand Down Expand Up @@ -63,5 +65,7 @@ CAML_ABSF_MASK:

.comm young_limit, 8

#ifdef SUPPORT_NOTE_GNU_STACK_NOEXEC
/* Mark stack as non-executable */
.section .note.GNU-stack,"",%progbits
#endif

0 comments on commit e0621f0

Please sign in to comment.