Skip to content

Commit

Permalink
Mark stack as non-executable in binaries produced by ccomp
Browse files Browse the repository at this point in the history
On Linux and BSD, add "stack not executable" annotations to every asm file
produced by ccomp or hand-written in the runtime support library.

Left for future work: adding the annotation to runtime/powerpc*/*.s .
(These files are not preprocessed, and must remain compatible with Diab.)
  • Loading branch information
xavierleroy committed Sep 2, 2024
1 parent facbe11 commit 82ef885
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/PrintAsm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ let print_program oc p =
List.iter (Printer.print_globdef oc) p.prog_defs;
Target.print_epilogue oc;
Printer.print_ais_annot oc;
print_nonexec_stack_note oc;
if !Clflags.option_g then
begin
let atom_to_s s =
Expand Down
9 changes: 9 additions & 0 deletions backend/PrintAsmaux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,12 @@ let macos_mergeable_string_section sz =
| 0 | 2 | 4 -> ".const"
| 1 -> ".cstring"
| _ -> assert false

(** Marking the stack as non executable *)

let print_nonexec_stack_note oc =
match Configuration.system with
| "linux" | "bsd" ->
output_string oc "\n\t.section .note.GNU-stack,\"\",%progbits\n"
| _ ->
()
4 changes: 4 additions & 0 deletions runtime/aarch64/sysdeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ _\name:
.type f, @function; .size f, . - f

#endif

#if defined(SYS_linux) || defined(SYS_bsd)
.section .note.GNU-stack,"",%progbits
#endif
4 changes: 4 additions & 0 deletions runtime/arm/sysdeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,7 @@
#define Reg3HI r7
#define Reg3LO r6
#endif

#if defined(SYS_linux) || defined(SYS_bsd)
.section .note.GNU-stack,"",%progbits
#endif
3 changes: 3 additions & 0 deletions runtime/riscV/sysdeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@

#endif

#if defined(SYS_linux) || defined(SYS_bsd)
.section .note.GNU-stack,"",%progbits
#endif
2 changes: 2 additions & 0 deletions runtime/x86_32/sysdeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#if defined(SYS_linux) || defined(SYS_bsd)

.section .note.GNU-stack,"",%progbits

#define GLOB(x) x
#define FUNCTION(f) \
.text; \
Expand Down
2 changes: 2 additions & 0 deletions runtime/x86_64/sysdeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#if defined(SYS_linux) || defined(SYS_bsd)

.section .note.GNU-stack,"",%progbits

#define GLOB(x) x
#define FUNCTION(f) \
.text; \
Expand Down

0 comments on commit 82ef885

Please sign in to comment.