Skip to content

Commit

Permalink
libc: Teach libc about the BTI elf note
Browse files Browse the repository at this point in the history
Add the Branch Target Identification (BTI) note to libc assembly
sources. As all obect files need the note for the library to have it
we need to insert it in all asm files.

Reviewed by:	emaste, markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D42228
  • Loading branch information
zxombie committed Nov 21, 2023
1 parent af37e28 commit 0895751
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/libc/aarch64/gen/_ctx_start.S
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
*/

#include <machine/asm.h>
#include <sys/elf_common.h>

ENTRY(_ctx_start)
blr x19 /* Call func from makecontext */
mov x0, x20 /* Load ucp saved in makecontext */
bl _C_LABEL(ctx_done)
bl _C_LABEL(abort)
END(_ctx_start)

GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
3 changes: 3 additions & 0 deletions lib/libc/aarch64/gen/_setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <machine/asm.h>
#include <machine/setjmp.h>
#include <sys/elf_common.h>

ENTRY(_setjmp)
/* Store the magic value and stack pointer */
Expand Down Expand Up @@ -101,3 +102,5 @@ botch:
bl _C_LABEL(abort)
#endif
END(_longjmp)

GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
4 changes: 4 additions & 0 deletions lib/libc/aarch64/gen/fabs.S
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
*/

#include <machine/asm.h>
#include <sys/elf_common.h>

ENTRY(fabs)
fabs d0, d0
ret
END(fabs)

GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
3 changes: 3 additions & 0 deletions lib/libc/aarch64/gen/setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <machine/asm.h>
#include <machine/setjmp.h>
#include <sys/elf_common.h>

ENTRY(setjmp)
sub sp, sp, #16
Expand Down Expand Up @@ -119,3 +120,5 @@ botch:
bl _C_LABEL(longjmperror)
bl _C_LABEL(abort)
END(longjmp)

GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
3 changes: 3 additions & 0 deletions lib/libc/aarch64/gen/sigsetjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <machine/asm.h>
#include <machine/setjmp.h>
#include <sys/elf_common.h>

ENTRY(sigsetjmp)
cmp x1, #0
Expand All @@ -52,3 +53,5 @@ ENTRY(siglongjmp)
.Lmagic:
.quad _JB_MAGIC__SETJMP
END(siglongjmp)

GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
4 changes: 4 additions & 0 deletions lib/libc/aarch64/string/memmove.S
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
* as it stops MISRCS from picking up the C implementation and rtld expects
* to copy the memmove object file into its object directory.
*/

#include <machine/asm.h>
#include <sys/elf_common.h>
GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
4 changes: 4 additions & 0 deletions lib/libc/aarch64/sys/cerror.S
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*/

#include <machine/asm.h>
#include <sys/elf_common.h>

ENTRY(cerror)
.hidden cerror
sub sp, sp, #16
Expand All @@ -37,3 +39,5 @@ ENTRY(cerror)
add sp, sp, #16
ret
END(cerror)

GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
3 changes: 3 additions & 0 deletions lib/libc/aarch64/sys/syscall.S
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
*/

#include <machine/asm.h>
#include <sys/elf_common.h>
#include "SYS.h"

RSYSCALL(syscall)

GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
3 changes: 3 additions & 0 deletions lib/libc/aarch64/sys/vfork.S
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#include <machine/asm.h>
#include <sys/elf_common.h>
#include "SYS.h"

ENTRY(__sys_vfork)
Expand All @@ -38,3 +39,5 @@ ENTRY(__sys_vfork)
mov lr, x2
ret
END(__sys_vfork)

GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
7 changes: 7 additions & 0 deletions lib/libc/sys/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,26 @@ NOTE_GNU_STACK='\t.section .note.GNU-stack,"",%%progbits\n'
.else
NOTE_GNU_STACK=''
.endif
.if ${MACHINE_CPUARCH} == "aarch64"
FEATURE_NOTE='\#include <sys/elf_common.h>\nGNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)'
.else
FEATURE_NOTE=''
.endif

${SASM}:
printf '/* %sgenerated by libc/sys/Makefile.inc */\n' @ > ${.TARGET}
printf '#include "compat.h"\n' >> ${.TARGET}
printf '#include "SYS.h"\nRSYSCALL(${.PREFIX})\n' >> ${.TARGET}
printf ${NOTE_GNU_STACK} >>${.TARGET}
printf ${FEATURE_NOTE} >> ${.TARGET}

${SPSEUDO}:
printf '/* %sgenerated by libc/sys/Makefile.inc */\n' @ > ${.TARGET}
printf '#include "compat.h"\n' >> ${.TARGET}
printf '#include "SYS.h"\nPSEUDO(${.PREFIX:S/_//})\n' \
>> ${.TARGET}
printf ${NOTE_GNU_STACK} >>${.TARGET}
printf ${FEATURE_NOTE} >> ${.TARGET}

MAN+= abort2.2 \
accept.2 \
Expand Down

0 comments on commit 0895751

Please sign in to comment.