mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH 0/4] Add CET IBT Support to MUSL
@ 2020-10-19 22:43 Joao Moreira
  2020-10-19 22:43 ` [musl] [PATCH 1/4] Support ASFLAGS in configure and Makefile Joao Moreira
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Joao Moreira @ 2020-10-19 22:43 UTC (permalink / raw)
  To: musl

Indirect Branch Tracking is an X86 feature which enforces that
indirect-branches to always target an endbranch instruction, confing the
execution flow of applications and protecting against control-flow hijacking
attacks. This patch series adds IBT support to MUSL.

Signed-off-by: Joao Moreira <joao.moreira@intel.com>

Joao Moreira (4):
  Support ASFLAGS in configure and Makefile
  Add ENDBRANCH64 and ENDBRANCH32 macro definitions
  Add endbr64 to x86_64 assembly functions
  Add endbr32 to i386 assembly functions

 Makefile                              |  4 ++--
 arch/x86_64/crt_arch.h                |  3 +++
 configure                             |  3 +++
 crt/i386/crti.s                       |  4 ++++
 crt/i386/crtn.s                       |  4 ++++
 crt/x86_64/crti.s                     |  4 ++++
 crt/x86_64/crtn.s                     |  4 ++++
 src/fenv/i386/fenv.s                  | 13 +++++++++++--
 src/fenv/x86_64/fenv.s                |  9 +++++++++
 src/include/ibt.s                     | 13 +++++++++++++
 src/ldso/i386/dlsym.s                 |  3 +++
 src/ldso/i386/tlsdesc.s               |  4 ++++
 src/ldso/x86_64/dlsym.s               |  3 +++
 src/ldso/x86_64/tlsdesc.s             |  4 ++++
 src/math/i386/acos.s                  |  2 ++
 src/math/i386/acosf.s                 |  3 +++
 src/math/i386/acosl.s                 |  3 +++
 src/math/i386/asin.s                  |  3 +++
 src/math/i386/asinf.s                 |  3 +++
 src/math/i386/asinl.s                 |  3 +++
 src/math/i386/atan.s                  |  3 +++
 src/math/i386/atan2.s                 |  3 +++
 src/math/i386/atan2f.s                |  3 +++
 src/math/i386/atan2l.s                |  3 +++
 src/math/i386/atanf.s                 |  3 +++
 src/math/i386/atanl.s                 |  2 ++
 src/math/i386/exp_ld.s                |  4 ++++
 src/math/i386/expl.s                  |  2 ++
 src/math/i386/floor.s                 | 11 +++++++++++
 src/math/i386/hypot.s                 |  3 +++
 src/math/i386/hypotf.s                |  3 +++
 src/math/i386/log.s                   |  3 +++
 src/math/i386/log10.s                 |  3 +++
 src/math/i386/log10f.s                |  3 +++
 src/math/i386/log10l.s                |  3 +++
 src/math/i386/log1p.s                 |  3 +++
 src/math/i386/log1pf.s                |  3 +++
 src/math/i386/log1pl.s                |  3 +++
 src/math/i386/log2.s                  |  3 +++
 src/math/i386/log2f.s                 |  3 +++
 src/math/i386/log2l.s                 |  3 +++
 src/math/i386/logf.s                  |  3 +++
 src/math/i386/logl.s                  |  3 +++
 src/math/i386/remquo.s                |  5 +++++
 src/math/i386/scalbn.s                |  5 +++++
 src/math/i386/scalbnf.s               |  5 +++++
 src/math/i386/scalbnl.s               |  5 +++++
 src/math/x86_64/acosl.s               |  2 ++
 src/math/x86_64/asinl.s               |  3 +++
 src/math/x86_64/atan2l.s              |  3 +++
 src/math/x86_64/atanl.s               |  3 +++
 src/math/x86_64/exp2l.s               |  4 ++++
 src/math/x86_64/expl.s                |  3 +++
 src/math/x86_64/floorl.s              |  5 +++++
 src/math/x86_64/log10l.s              |  3 +++
 src/math/x86_64/log1pl.s              |  3 +++
 src/math/x86_64/log2l.s               |  3 +++
 src/math/x86_64/logl.s                |  3 +++
 src/process/i386/vfork.s              |  3 +++
 src/process/x86_64/vfork.s            |  3 +++
 src/setjmp/i386/longjmp.s             |  3 +++
 src/setjmp/i386/setjmp.s              |  3 +++
 src/setjmp/x86_64/longjmp.s           |  3 +++
 src/setjmp/x86_64/setjmp.s            |  3 +++
 src/signal/i386/restore.s             |  4 ++++
 src/signal/i386/sigsetjmp.s           |  3 +++
 src/signal/x86_64/restore.s           |  3 +++
 src/signal/x86_64/sigsetjmp.s         |  3 +++
 src/string/i386/memcpy.s              |  3 +++
 src/string/i386/memmove.s             |  3 +++
 src/string/i386/memset.s              |  7 +++++--
 src/string/x86_64/memcpy.s            |  3 +++
 src/string/x86_64/memmove.s           |  3 +++
 src/string/x86_64/memset.s            |  3 +++
 src/thread/i386/__set_thread_area.s   |  3 +++
 src/thread/i386/__unmapself.s         |  3 +++
 src/thread/i386/clone.s               |  3 +++
 src/thread/i386/syscall_cp.s          |  3 +++
 src/thread/i386/tls.s                 |  3 +++
 src/thread/x86_64/__set_thread_area.s |  3 +++
 src/thread/x86_64/__unmapself.s       |  3 +++
 src/thread/x86_64/clone.s             |  3 +++
 src/thread/x86_64/syscall_cp.s        |  4 +++-
 83 files changed, 297 insertions(+), 7 deletions(-)
 create mode 100644 src/include/ibt.s

-- 
2.27.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [musl] [PATCH 1/4] Support ASFLAGS in configure and Makefile
  2020-10-19 22:43 [musl] [PATCH 0/4] Add CET IBT Support to MUSL Joao Moreira
@ 2020-10-19 22:43 ` Joao Moreira
  2020-10-19 22:43 ` [musl] [PATCH 2/4] Add ENDBRANCH64 and ENDBRANCH32 macro definitions Joao Moreira
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Joao Moreira @ 2020-10-19 22:43 UTC (permalink / raw)
  To: musl

Currently MUSL does not support setting ASFLAGS (assembler flags) through
configure. Thus, add support to ASFLAGS, which are passed similarly as CFLAGS.

Signed-off-by: Joao Moreira <joao.moreira@intel.com>
---
 Makefile  | 4 ++--
 configure | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index e8cc4436..f75a946d 100644
--- a/Makefile
+++ b/Makefile
@@ -135,9 +135,9 @@ CC_CMD = $(CC) $(CFLAGS_ALL) -c -o $@ $<
 
 # Choose invocation of assembler to be used
 ifeq ($(ADD_CFI),yes)
-	AS_CMD = LC_ALL=C awk -f $(srcdir)/tools/add-cfi.common.awk -f $(srcdir)/tools/add-cfi.$(ARCH).awk $< | $(CC) $(CFLAGS_ALL) -x assembler -c -o $@ -
+	AS_CMD = LC_ALL=C awk -f $(srcdir)/tools/add-cfi.common.awk -f $(srcdir)/tools/add-cfi.$(ARCH).awk $< | $(CC) $(CFLAGS_ALL) $(ASFLAGS) -x assembler -c -o $@ -
 else
-	AS_CMD = $(CC_CMD)
+	AS_CMD = $(CC_CMD) $(ASFLAGS)
 endif
 
 obj/%.o: $(srcdir)/%.s
diff --git a/configure b/configure
index 947adf41..4ad78b27 100755
--- a/configure
+++ b/configure
@@ -41,6 +41,7 @@ Optional packages:
 Some influential environment variables:
   CC                      C compiler command [detected]
   CFLAGS                  C compiler flags [-Os -pipe ...]
+  ASFLAGS                 Assembler flags [none]
   CROSS_COMPILE           prefix for cross compiler and tools [none]
   LIBCC                   compiler runtime library [detected]
 
@@ -181,6 +182,7 @@ AR=*) AR=${arg#*=} ;;
 RANLIB=*) RANLIB=${arg#*=} ;;
 CC=*) CC=${arg#*=} ;;
 CFLAGS=*) CFLAGS=${arg#*=} ;;
+ASFLAGS=*) ASFLAGS=${arg#*=} ;;
 CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
 LDFLAGS=*) LDFLAGS=${arg#*=} ;;
 CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
@@ -787,6 +789,7 @@ includedir = $includedir
 syslibdir = $syslibdir
 CC = $CC
 CFLAGS = $CFLAGS
+ASFLAGS = $ASFLAGS
 CFLAGS_AUTO = $CFLAGS_AUTO
 CFLAGS_C99FSE = $CFLAGS_C99FSE
 CFLAGS_MEMOPS = $CFLAGS_MEMOPS
-- 
2.27.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [musl] [PATCH 2/4] Add ENDBRANCH64 and ENDBRANCH32 macro definitions
  2020-10-19 22:43 [musl] [PATCH 0/4] Add CET IBT Support to MUSL Joao Moreira
  2020-10-19 22:43 ` [musl] [PATCH 1/4] Support ASFLAGS in configure and Makefile Joao Moreira
@ 2020-10-19 22:43 ` Joao Moreira
  2020-10-19 22:43 ` [musl] [PATCH 3/4] Add endbr64 to x86_64 assembly functions Joao Moreira
  2020-10-19 22:43 ` [musl] [PATCH 4/4] Add endbr32 to i386 " Joao Moreira
  3 siblings, 0 replies; 5+ messages in thread
From: Joao Moreira @ 2020-10-19 22:43 UTC (permalink / raw)
  To: musl

Define ENDBRANCH64 and ENDBRANCH32 macros to endbr64 and endbr32 instructions,
respectively, in case the flag CET_IBT is set. If the flag is not set, the
macros are defined to nothing.

These macros will later be used to properly add endbranch instruction to
x86 and i386 assembly functions.

Signed-off-by: Joao Moreira <joao.moreira@intel.com>
---
 src/include/ibt.s | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 src/include/ibt.s

diff --git a/src/include/ibt.s b/src/include/ibt.s
new file mode 100644
index 00000000..2f16006f
--- /dev/null
+++ b/src/include/ibt.s
@@ -0,0 +1,13 @@
+.ifdef CET_IBT
+	.macro ENDBRANCH64
+		endbr64
+	.endm
+	.macro ENDBRANCH32
+		endbr32
+	.endm
+.else
+	.macro ENDBRANCH64
+	.endm
+	.macro ENDBRANCH32
+	.endm
+.endif
-- 
2.27.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [musl] [PATCH 3/4] Add endbr64 to x86_64 assembly functions
  2020-10-19 22:43 [musl] [PATCH 0/4] Add CET IBT Support to MUSL Joao Moreira
  2020-10-19 22:43 ` [musl] [PATCH 1/4] Support ASFLAGS in configure and Makefile Joao Moreira
  2020-10-19 22:43 ` [musl] [PATCH 2/4] Add ENDBRANCH64 and ENDBRANCH32 macro definitions Joao Moreira
@ 2020-10-19 22:43 ` Joao Moreira
  2020-10-19 22:43 ` [musl] [PATCH 4/4] Add endbr32 to i386 " Joao Moreira
  3 siblings, 0 replies; 5+ messages in thread
From: Joao Moreira @ 2020-10-19 22:43 UTC (permalink / raw)
  To: musl

Include ibt.s file in x86_64 assembly files. This file contains the macro
definitions for endbr64 instructions and is placed in the beginning of each
assembly function. If CET_IBT is not defined for compilation, the macro is
defined to nothing and the generated binary is not affected.

Signed-off-by: Joao Moreira <joao.moreira@intel.com>
---
 arch/x86_64/crt_arch.h                | 3 +++
 crt/x86_64/crti.s                     | 4 ++++
 crt/x86_64/crtn.s                     | 4 ++++
 src/fenv/x86_64/fenv.s                | 9 +++++++++
 src/ldso/x86_64/dlsym.s               | 3 +++
 src/ldso/x86_64/tlsdesc.s             | 4 ++++
 src/math/x86_64/acosl.s               | 2 ++
 src/math/x86_64/asinl.s               | 3 +++
 src/math/x86_64/atan2l.s              | 3 +++
 src/math/x86_64/atanl.s               | 3 +++
 src/math/x86_64/exp2l.s               | 4 ++++
 src/math/x86_64/expl.s                | 3 +++
 src/math/x86_64/floorl.s              | 5 +++++
 src/math/x86_64/log10l.s              | 3 +++
 src/math/x86_64/log1pl.s              | 3 +++
 src/math/x86_64/log2l.s               | 3 +++
 src/math/x86_64/logl.s                | 3 +++
 src/process/x86_64/vfork.s            | 3 +++
 src/setjmp/x86_64/longjmp.s           | 3 +++
 src/setjmp/x86_64/setjmp.s            | 3 +++
 src/signal/x86_64/restore.s           | 3 +++
 src/signal/x86_64/sigsetjmp.s         | 3 +++
 src/string/x86_64/memcpy.s            | 3 +++
 src/string/x86_64/memmove.s           | 3 +++
 src/string/x86_64/memset.s            | 3 +++
 src/thread/x86_64/__set_thread_area.s | 3 +++
 src/thread/x86_64/__unmapself.s       | 3 +++
 src/thread/x86_64/clone.s             | 3 +++
 src/thread/x86_64/syscall_cp.s        | 4 +++-
 29 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/arch/x86_64/crt_arch.h b/arch/x86_64/crt_arch.h
index 3eec61bd..c54fa073 100644
--- a/arch/x86_64/crt_arch.h
+++ b/arch/x86_64/crt_arch.h
@@ -2,6 +2,9 @@ __asm__(
 ".text \n"
 ".global " START " \n"
 START ": \n"
+#ifdef CET_IBT
+" endbr64 \n"
+#endif
 "	xor %rbp,%rbp \n"
 "	mov %rsp,%rdi \n"
 ".weak _DYNAMIC \n"
diff --git a/crt/x86_64/crti.s b/crt/x86_64/crti.s
index 4788968b..fbc7e479 100644
--- a/crt/x86_64/crti.s
+++ b/crt/x86_64/crti.s
@@ -1,9 +1,13 @@
+.include "ibt.s"
+
 .section .init
 .global _init
 _init:
+	ENDBRANCH64
 	push %rax
 
 .section .fini
 .global _fini
 _fini:
+	ENDBRANCH64
 	push %rax
diff --git a/crt/x86_64/crtn.s b/crt/x86_64/crtn.s
index 29198b77..87f85fae 100644
--- a/crt/x86_64/crtn.s
+++ b/crt/x86_64/crtn.s
@@ -1,7 +1,11 @@
+.include "ibt.s"
+
 .section .init
+	ENDBRANCH64
 	pop %rax
 	ret
 
 .section .fini
+	ENDBRANCH64
 	pop %rax
 	ret
diff --git a/src/fenv/x86_64/fenv.s b/src/fenv/x86_64/fenv.s
index 98d876da..7b47f5d0 100644
--- a/src/fenv/x86_64/fenv.s
+++ b/src/fenv/x86_64/fenv.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global feclearexcept
 .type feclearexcept,@function
 feclearexcept:
+	ENDBRANCH64
 		# maintain exceptions in the sse mxcsr, clear x87 exceptions
 	mov %edi,%ecx
 	and $0x3f,%ecx
@@ -22,6 +25,7 @@ feclearexcept:
 .global feraiseexcept
 .type feraiseexcept,@function
 feraiseexcept:
+	ENDBRANCH64
 	and $0x3f,%edi
 	stmxcsr -8(%rsp)
 	or %edi,-8(%rsp)
@@ -33,6 +37,7 @@ feraiseexcept:
 .hidden __fesetround
 .type __fesetround,@function
 __fesetround:
+	ENDBRANCH64
 	push %rax
 	xor %eax,%eax
 	mov %edi,%ecx
@@ -51,6 +56,7 @@ __fesetround:
 .global fegetround
 .type fegetround,@function
 fegetround:
+	ENDBRANCH64
 	push %rax
 	stmxcsr (%rsp)
 	pop %rax
@@ -61,6 +67,7 @@ fegetround:
 .global fegetenv
 .type fegetenv,@function
 fegetenv:
+	ENDBRANCH64
 	xor %eax,%eax
 	fnstenv (%rdi)
 	stmxcsr 28(%rdi)
@@ -69,6 +76,7 @@ fegetenv:
 .global fesetenv
 .type fesetenv,@function
 fesetenv:
+	ENDBRANCH64
 	xor %eax,%eax
 	inc %rdi
 	jz 1f
@@ -88,6 +96,7 @@ fesetenv:
 .global fetestexcept
 .type fetestexcept,@function
 fetestexcept:
+	ENDBRANCH64
 	and $0x3f,%edi
 	push %rax
 	stmxcsr (%rsp)
diff --git a/src/ldso/x86_64/dlsym.s b/src/ldso/x86_64/dlsym.s
index d840b955..ada2fefd 100644
--- a/src/ldso/x86_64/dlsym.s
+++ b/src/ldso/x86_64/dlsym.s
@@ -1,7 +1,10 @@
+.include "ibt.s"
+
 .text
 .global dlsym
 .hidden __dlsym
 .type dlsym,@function
 dlsym:
+	ENDBRANCH64
 	mov (%rsp),%rdx
 	jmp __dlsym
diff --git a/src/ldso/x86_64/tlsdesc.s b/src/ldso/x86_64/tlsdesc.s
index e08f1d7d..a608d68f 100644
--- a/src/ldso/x86_64/tlsdesc.s
+++ b/src/ldso/x86_64/tlsdesc.s
@@ -1,8 +1,11 @@
+.include "ibt.s"
+
 .text
 .global __tlsdesc_static
 .hidden __tlsdesc_static
 .type __tlsdesc_static,@function
 __tlsdesc_static:
+	ENDBRANCH64
 	mov 8(%rax),%rax
 	ret
 
@@ -10,6 +13,7 @@ __tlsdesc_static:
 .hidden __tlsdesc_dynamic
 .type __tlsdesc_dynamic,@function
 __tlsdesc_dynamic:
+	ENDBRANCH64
 	mov 8(%rax),%rax
 	push %rdx
 	mov %fs:8,%rdx
diff --git a/src/math/x86_64/acosl.s b/src/math/x86_64/acosl.s
index 88e01b49..9a4da9a3 100644
--- a/src/math/x86_64/acosl.s
+++ b/src/math/x86_64/acosl.s
@@ -1,8 +1,10 @@
 # see ../i386/acos.s
+.include "ibt.s"
 
 .global acosl
 .type acosl,@function
 acosl:
+	ENDBRANCH64
 	fldt 8(%rsp)
 1:	fld %st(0)
 	fld1
diff --git a/src/math/x86_64/asinl.s b/src/math/x86_64/asinl.s
index ed212d9a..38ea6cd1 100644
--- a/src/math/x86_64/asinl.s
+++ b/src/math/x86_64/asinl.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global asinl
 .type asinl,@function
 asinl:
+	ENDBRANCH64
 	fldt 8(%rsp)
 1:	fld %st(0)
 	fld1
diff --git a/src/math/x86_64/atan2l.s b/src/math/x86_64/atan2l.s
index e5f0a3de..1ffb8705 100644
--- a/src/math/x86_64/atan2l.s
+++ b/src/math/x86_64/atan2l.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global atan2l
 .type atan2l,@function
 atan2l:
+	ENDBRANCH64
 	fldt 8(%rsp)
 	fldt 24(%rsp)
 	fpatan
diff --git a/src/math/x86_64/atanl.s b/src/math/x86_64/atanl.s
index df76de5d..0b06fe2e 100644
--- a/src/math/x86_64/atanl.s
+++ b/src/math/x86_64/atanl.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global atanl
 .type atanl,@function
 atanl:
+	ENDBRANCH64
 	fldt 8(%rsp)
 	fld1
 	fpatan
diff --git a/src/math/x86_64/exp2l.s b/src/math/x86_64/exp2l.s
index effab2bd..b2b5fa30 100644
--- a/src/math/x86_64/exp2l.s
+++ b/src/math/x86_64/exp2l.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global expm1l
 .type expm1l,@function
 expm1l:
+	ENDBRANCH64
 	fldt 8(%rsp)
 	fldl2e
 	fmulp
@@ -30,6 +33,7 @@ expm1l:
 .global exp2l
 .type exp2l,@function
 exp2l:
+	ENDBRANCH64
 	fldt 8(%rsp)
 1:	fld %st(0)
 	sub $16,%rsp
diff --git a/src/math/x86_64/expl.s b/src/math/x86_64/expl.s
index 798261d2..99444dc9 100644
--- a/src/math/x86_64/expl.s
+++ b/src/math/x86_64/expl.s
@@ -1,3 +1,5 @@
+.include "ibt.s"
+
 # exp(x) = 2^hi + 2^hi (2^lo - 1)
 # where hi+lo = log2e*x with 128bit precision
 # exact log2e*x calculation depends on nearest rounding mode
@@ -6,6 +8,7 @@
 .global expl
 .type expl,@function
 expl:
+	ENDBRANCH64
 	fldt 8(%rsp)
 
 		# interesting case: 0x1p-32 <= |x| < 16384
diff --git a/src/math/x86_64/floorl.s b/src/math/x86_64/floorl.s
index 80da4660..191b47e4 100644
--- a/src/math/x86_64/floorl.s
+++ b/src/math/x86_64/floorl.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global floorl
 .type floorl,@function
 floorl:
+	ENDBRANCH64
 	fldt 8(%rsp)
 1:	mov $0x7,%al
 1:	fstcw 8(%rsp)
@@ -15,6 +18,7 @@ floorl:
 .global ceill
 .type ceill,@function
 ceill:
+	ENDBRANCH64
 	fldt 8(%rsp)
 	mov $0xb,%al
 	jmp 1b
@@ -22,6 +26,7 @@ ceill:
 .global truncl
 .type truncl,@function
 truncl:
+	ENDBRANCH64
 	fldt 8(%rsp)
 	mov $0xf,%al
 	jmp 1b
diff --git a/src/math/x86_64/log10l.s b/src/math/x86_64/log10l.s
index 48ea4af7..23eb3d4b 100644
--- a/src/math/x86_64/log10l.s
+++ b/src/math/x86_64/log10l.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log10l
 .type log10l,@function
 log10l:
+	ENDBRANCH64
 	fldlg2
 	fldt 8(%rsp)
 	fyl2x
diff --git a/src/math/x86_64/log1pl.s b/src/math/x86_64/log1pl.s
index 955c9dbf..5d7793ae 100644
--- a/src/math/x86_64/log1pl.s
+++ b/src/math/x86_64/log1pl.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log1pl
 .type log1pl,@function
 log1pl:
+	ENDBRANCH64
 	mov 14(%rsp),%eax
 	fldln2
 	and $0x7fffffff,%eax
diff --git a/src/math/x86_64/log2l.s b/src/math/x86_64/log2l.s
index ba08b9fb..38e848bd 100644
--- a/src/math/x86_64/log2l.s
+++ b/src/math/x86_64/log2l.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log2l
 .type log2l,@function
 log2l:
+	ENDBRANCH64
 	fld1
 	fldt 8(%rsp)
 	fyl2x
diff --git a/src/math/x86_64/logl.s b/src/math/x86_64/logl.s
index 20dd1f81..24f58e1f 100644
--- a/src/math/x86_64/logl.s
+++ b/src/math/x86_64/logl.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global logl
 .type logl,@function
 logl:
+	ENDBRANCH64
 	fldln2
 	fldt 8(%rsp)
 	fyl2x
diff --git a/src/process/x86_64/vfork.s b/src/process/x86_64/vfork.s
index 91144390..6c141a6b 100644
--- a/src/process/x86_64/vfork.s
+++ b/src/process/x86_64/vfork.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global vfork
 .type vfork,@function
 vfork:
+	ENDBRANCH64
 	pop %rdx
 	mov $58,%eax
 	syscall
diff --git a/src/setjmp/x86_64/longjmp.s b/src/setjmp/x86_64/longjmp.s
index 1b2661c3..4f2bbc8c 100644
--- a/src/setjmp/x86_64/longjmp.s
+++ b/src/setjmp/x86_64/longjmp.s
@@ -1,10 +1,13 @@
 /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
+.include "ibt.s"
+
 .global _longjmp
 .global longjmp
 .type _longjmp,@function
 .type longjmp,@function
 _longjmp:
 longjmp:
+	ENDBRANCH64
 	xor %eax,%eax
 	cmp $1,%esi             /* CF = val ? 0 : 1 */
 	adc %esi,%eax           /* eax = val + !val */
diff --git a/src/setjmp/x86_64/setjmp.s b/src/setjmp/x86_64/setjmp.s
index d95e4853..3a9f6fd6 100644
--- a/src/setjmp/x86_64/setjmp.s
+++ b/src/setjmp/x86_64/setjmp.s
@@ -1,4 +1,6 @@
 /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
+.include "ibt.s"
+
 .global __setjmp
 .global _setjmp
 .global setjmp
@@ -8,6 +10,7 @@
 __setjmp:
 _setjmp:
 setjmp:
+	ENDBRANCH64
 	mov %rbx,(%rdi)         /* rdi is jmp_buf, move registers onto it */
 	mov %rbp,8(%rdi)
 	mov %r12,16(%rdi)
diff --git a/src/signal/x86_64/restore.s b/src/signal/x86_64/restore.s
index 27d6cf31..f6bda936 100644
--- a/src/signal/x86_64/restore.s
+++ b/src/signal/x86_64/restore.s
@@ -1,8 +1,11 @@
+.include "ibt.s"
+
 	nop
 .global __restore_rt
 .hidden __restore_rt
 .type __restore_rt,@function
 __restore_rt:
+	ENDBRANCH64
 	mov $15, %rax
 	syscall
 .size __restore_rt,.-__restore_rt
diff --git a/src/signal/x86_64/sigsetjmp.s b/src/signal/x86_64/sigsetjmp.s
index 9a7695f9..91f33f19 100644
--- a/src/signal/x86_64/sigsetjmp.s
+++ b/src/signal/x86_64/sigsetjmp.s
@@ -1,9 +1,12 @@
+.include "ibt.s"
+
 .global sigsetjmp
 .global __sigsetjmp
 .type sigsetjmp,@function
 .type __sigsetjmp,@function
 sigsetjmp:
 __sigsetjmp:
+	ENDBRANCH64
 	test %esi,%esi
 	jz 1f
 
diff --git a/src/string/x86_64/memcpy.s b/src/string/x86_64/memcpy.s
index 3d960efa..374235c8 100644
--- a/src/string/x86_64/memcpy.s
+++ b/src/string/x86_64/memcpy.s
@@ -1,8 +1,11 @@
+.include "ibt.s"
+
 .global memcpy
 .global __memcpy_fwd
 .hidden __memcpy_fwd
 .type memcpy,@function
 memcpy:
+	ENDBRANCH64
 __memcpy_fwd:
 	mov %rdi,%rax
 	cmp $8,%rdx
diff --git a/src/string/x86_64/memmove.s b/src/string/x86_64/memmove.s
index 172c0252..4782daa1 100644
--- a/src/string/x86_64/memmove.s
+++ b/src/string/x86_64/memmove.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global memmove
 .type memmove,@function
 memmove:
+	ENDBRANCH64
 	mov %rdi,%rax
 	sub %rsi,%rax
 	cmp %rdx,%rax
diff --git a/src/string/x86_64/memset.s b/src/string/x86_64/memset.s
index 2d3f5e52..802d2e8b 100644
--- a/src/string/x86_64/memset.s
+++ b/src/string/x86_64/memset.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global memset
 .type memset,@function
 memset:
+	ENDBRANCH64
 	movzbq %sil,%rax
 	mov $0x101010101010101,%r8
 	imul %r8,%rax
diff --git a/src/thread/x86_64/__set_thread_area.s b/src/thread/x86_64/__set_thread_area.s
index 7347ff4d..299845a6 100644
--- a/src/thread/x86_64/__set_thread_area.s
+++ b/src/thread/x86_64/__set_thread_area.s
@@ -1,9 +1,12 @@
 /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
+.include "ibt.s"
+
 .text
 .global __set_thread_area
 .hidden __set_thread_area
 .type __set_thread_area,@function
 __set_thread_area:
+	ENDBRANCH64
 	mov %rdi,%rsi           /* shift for syscall */
 	movl $0x1002,%edi       /* SET_FS register */
 	movl $158,%eax          /* set fs segment to */
diff --git a/src/thread/x86_64/__unmapself.s b/src/thread/x86_64/__unmapself.s
index e2689e65..dfb84a13 100644
--- a/src/thread/x86_64/__unmapself.s
+++ b/src/thread/x86_64/__unmapself.s
@@ -1,8 +1,11 @@
 /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */
+.include "ibt.s"
+
 .text
 .global __unmapself
 .type   __unmapself,@function
 __unmapself:
+	ENDBRANCH64
 	movl $11,%eax   /* SYS_munmap */
 	syscall         /* munmap(arg2,arg3) */
 	xor %rdi,%rdi   /* exit() args: always return success */
diff --git a/src/thread/x86_64/clone.s b/src/thread/x86_64/clone.s
index 6e47bc0a..6b79832c 100644
--- a/src/thread/x86_64/clone.s
+++ b/src/thread/x86_64/clone.s
@@ -1,8 +1,11 @@
+.include "ibt.s"
+
 .text
 .global __clone
 .hidden __clone
 .type   __clone,@function
 __clone:
+	ENDBRANCH64
 	xor %eax,%eax
 	mov $56,%al
 	mov %rdi,%r11
diff --git a/src/thread/x86_64/syscall_cp.s b/src/thread/x86_64/syscall_cp.s
index 4f101716..b14ed3e4 100644
--- a/src/thread/x86_64/syscall_cp.s
+++ b/src/thread/x86_64/syscall_cp.s
@@ -1,3 +1,5 @@
+.include "ibt.s"
+
 .text
 .global __cp_begin
 .hidden __cp_begin
@@ -10,7 +12,7 @@
 .hidden __syscall_cp_asm
 .type   __syscall_cp_asm,@function
 __syscall_cp_asm:
-
+	ENDBRANCH64
 __cp_begin:
 	mov (%rdi),%eax
 	test %eax,%eax
-- 
2.27.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [musl] [PATCH 4/4] Add endbr32 to i386 assembly functions
  2020-10-19 22:43 [musl] [PATCH 0/4] Add CET IBT Support to MUSL Joao Moreira
                   ` (2 preceding siblings ...)
  2020-10-19 22:43 ` [musl] [PATCH 3/4] Add endbr64 to x86_64 assembly functions Joao Moreira
@ 2020-10-19 22:43 ` Joao Moreira
  3 siblings, 0 replies; 5+ messages in thread
From: Joao Moreira @ 2020-10-19 22:43 UTC (permalink / raw)
  To: musl

Include ibt.s file in i386 assembly files. This file contains the macro
definitions for endbr32 instructions and is placed in the beginning of each
assembly function. If CET_IBT is not defined for compilation, the macro is
defined to nothing and the generated binary is not affected.

Signed-off-by: Joao Moreira <joao.moreira@intel.com>
---
 crt/i386/crti.s                     |  4 ++++
 crt/i386/crtn.s                     |  4 ++++
 src/fenv/i386/fenv.s                | 13 +++++++++++--
 src/ldso/i386/dlsym.s               |  3 +++
 src/ldso/i386/tlsdesc.s             |  4 ++++
 src/math/i386/acos.s                |  2 ++
 src/math/i386/acosf.s               |  3 +++
 src/math/i386/acosl.s               |  3 +++
 src/math/i386/asin.s                |  3 +++
 src/math/i386/asinf.s               |  3 +++
 src/math/i386/asinl.s               |  3 +++
 src/math/i386/atan.s                |  3 +++
 src/math/i386/atan2.s               |  3 +++
 src/math/i386/atan2f.s              |  3 +++
 src/math/i386/atan2l.s              |  3 +++
 src/math/i386/atanf.s               |  3 +++
 src/math/i386/atanl.s               |  2 ++
 src/math/i386/exp_ld.s              |  4 ++++
 src/math/i386/expl.s                |  2 ++
 src/math/i386/floor.s               | 11 +++++++++++
 src/math/i386/hypot.s               |  3 +++
 src/math/i386/hypotf.s              |  3 +++
 src/math/i386/log.s                 |  3 +++
 src/math/i386/log10.s               |  3 +++
 src/math/i386/log10f.s              |  3 +++
 src/math/i386/log10l.s              |  3 +++
 src/math/i386/log1p.s               |  3 +++
 src/math/i386/log1pf.s              |  3 +++
 src/math/i386/log1pl.s              |  3 +++
 src/math/i386/log2.s                |  3 +++
 src/math/i386/log2f.s               |  3 +++
 src/math/i386/log2l.s               |  3 +++
 src/math/i386/logf.s                |  3 +++
 src/math/i386/logl.s                |  3 +++
 src/math/i386/remquo.s              |  5 +++++
 src/math/i386/scalbn.s              |  5 +++++
 src/math/i386/scalbnf.s             |  5 +++++
 src/math/i386/scalbnl.s             |  5 +++++
 src/process/i386/vfork.s            |  3 +++
 src/setjmp/i386/longjmp.s           |  3 +++
 src/setjmp/i386/setjmp.s            |  3 +++
 src/signal/i386/restore.s           |  4 ++++
 src/signal/i386/sigsetjmp.s         |  3 +++
 src/string/i386/memcpy.s            |  3 +++
 src/string/i386/memmove.s           |  3 +++
 src/string/i386/memset.s            |  7 +++++--
 src/thread/i386/__set_thread_area.s |  3 +++
 src/thread/i386/__unmapself.s       |  3 +++
 src/thread/i386/clone.s             |  3 +++
 src/thread/i386/syscall_cp.s        |  3 +++
 src/thread/i386/tls.s               |  3 +++
 51 files changed, 181 insertions(+), 4 deletions(-)

diff --git a/crt/i386/crti.s b/crt/i386/crti.s
index d2682a20..9db4dd9c 100644
--- a/crt/i386/crti.s
+++ b/crt/i386/crti.s
@@ -1,9 +1,13 @@
+.include "ibt.s"
+
 .section .init
 .global _init
 _init:
+	ENDBRANCH32
 	sub $12,%esp
 
 .section .fini
 .global _fini
 _fini:
+	ENDBRANCH32
 	sub $12,%esp
diff --git a/crt/i386/crtn.s b/crt/i386/crtn.s
index f3b61e01..6010ec16 100644
--- a/crt/i386/crtn.s
+++ b/crt/i386/crtn.s
@@ -1,7 +1,11 @@
+.include "ibt.s"
+
 .section .init
+	ENDBRANCH32
 	add $12,%esp
 	ret
 
 .section .fini
+	ENDBRANCH32
 	add $12,%esp
 	ret
diff --git a/src/fenv/i386/fenv.s b/src/fenv/i386/fenv.s
index e7f7932a..1da507a5 100644
--- a/src/fenv/i386/fenv.s
+++ b/src/fenv/i386/fenv.s
@@ -1,8 +1,11 @@
+.include "ibt.s"
+
 .hidden __hwcap
 
 .global feclearexcept
 .type feclearexcept,@function
-feclearexcept:	
+feclearexcept:
+	ENDBRANCH32
 	mov 4(%esp),%ecx
 	and $0x3f,%ecx
 	fnstsw %ax
@@ -49,7 +52,8 @@ feclearexcept:
 
 .global feraiseexcept
 .type feraiseexcept,@function
-feraiseexcept:	
+feraiseexcept
+	ENDBRANCH32
 	mov 4(%esp),%eax
 	and $0x3f,%eax
 	sub $32,%esp
@@ -64,6 +68,7 @@ feraiseexcept:
 .hidden __fesetround
 .type __fesetround,@function
 __fesetround:
+	ENDBRANCH32
 	mov 4(%esp),%ecx
 	push %eax
 	xor %eax,%eax
@@ -88,6 +93,7 @@ __fesetround:
 .global fegetround
 .type fegetround,@function
 fegetround:
+	ENDBRANCH32
 	push %eax
 	fnstcw (%esp)
 	pop %eax
@@ -97,6 +103,7 @@ fegetround:
 .global fegetenv
 .type fegetenv,@function
 fegetenv:
+	ENDBRANCH32
 	mov 4(%esp),%ecx
 	xor %eax,%eax
 	fnstenv (%ecx)
@@ -116,6 +123,7 @@ fegetenv:
 .global fesetenv
 .type fesetenv,@function
 fesetenv:
+	ENDBRANCH32
 	mov 4(%esp),%ecx
 	xor %eax,%eax
 	inc %ecx
@@ -149,6 +157,7 @@ fesetenv:
 .global fetestexcept
 .type fetestexcept,@function
 fetestexcept:
+	ENDBRANCH32
 	mov 4(%esp),%ecx
 	and $0x3f,%ecx
 	fnstsw %ax
diff --git a/src/ldso/i386/dlsym.s b/src/ldso/i386/dlsym.s
index 097e30ce..5dfa182d 100644
--- a/src/ldso/i386/dlsym.s
+++ b/src/ldso/i386/dlsym.s
@@ -1,8 +1,11 @@
+.include "ibt.s"
+
 .text
 .global dlsym
 .hidden __dlsym
 .type dlsym,@function
 dlsym:
+	ENDBRANCH32
 	push (%esp)
 	push 12(%esp)
 	push 12(%esp)
diff --git a/src/ldso/i386/tlsdesc.s b/src/ldso/i386/tlsdesc.s
index 32c81766..09f6474e 100644
--- a/src/ldso/i386/tlsdesc.s
+++ b/src/ldso/i386/tlsdesc.s
@@ -1,8 +1,11 @@
+.include "ibt.s"
+
 .text
 .global __tlsdesc_static
 .hidden __tlsdesc_static
 .type __tlsdesc_static,@function
 __tlsdesc_static:
+	ENDBRANCH32
 	mov 4(%eax),%eax
 	ret
 
@@ -10,6 +13,7 @@ __tlsdesc_static:
 .hidden __tlsdesc_dynamic
 .type __tlsdesc_dynamic,@function
 __tlsdesc_dynamic:
+	ENDBRANCH32
 	mov 4(%eax),%eax
 	push %edx
 	mov %gs:4,%edx
diff --git a/src/math/i386/acos.s b/src/math/i386/acos.s
index af423a2f..f3a975b5 100644
--- a/src/math/i386/acos.s
+++ b/src/math/i386/acos.s
@@ -1,8 +1,10 @@
+.include "ibt.s"
 # use acos(x) = atan2(fabs(sqrt((1-x)*(1+x))), x)
 
 .global acos
 .type acos,@function
 acos:
+	ENDBRANCH32
 	fldl 4(%esp)
 	fld %st(0)
 	fld1
diff --git a/src/math/i386/acosf.s b/src/math/i386/acosf.s
index d2cdfdbf..697b1255 100644
--- a/src/math/i386/acosf.s
+++ b/src/math/i386/acosf.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global acosf
 .type acosf,@function
 acosf:
+	ENDBRANCH32
 	flds 4(%esp)
 	fld %st(0)
 	fld1
diff --git a/src/math/i386/acosl.s b/src/math/i386/acosl.s
index 599c8230..d455a9a9 100644
--- a/src/math/i386/acosl.s
+++ b/src/math/i386/acosl.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global acosl
 .type acosl,@function
 acosl:
+	ENDBRANCH32
 	fldt 4(%esp)
 	fld %st(0)
 	fld1
diff --git a/src/math/i386/asin.s b/src/math/i386/asin.s
index 2bc8356f..bec105d1 100644
--- a/src/math/i386/asin.s
+++ b/src/math/i386/asin.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global asin
 .type asin,@function
 asin:
+	ENDBRANCH32
 	fldl 4(%esp)
 	mov 8(%esp),%eax
 	add %eax,%eax
diff --git a/src/math/i386/asinf.s b/src/math/i386/asinf.s
index 05909753..28b59e61 100644
--- a/src/math/i386/asinf.s
+++ b/src/math/i386/asinf.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global asinf
 .type asinf,@function
 asinf:
+	ENDBRANCH32
 	flds 4(%esp)
 	mov 4(%esp),%eax
 	add %eax,%eax
diff --git a/src/math/i386/asinl.s b/src/math/i386/asinl.s
index e973fc85..d1a0a0ae 100644
--- a/src/math/i386/asinl.s
+++ b/src/math/i386/asinl.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global asinl
 .type asinl,@function
 asinl:
+	ENDBRANCH32
 	fldt 4(%esp)
 	fld %st(0)
 	fld1
diff --git a/src/math/i386/atan.s b/src/math/i386/atan.s
index 2c57f6b3..caf27242 100644
--- a/src/math/i386/atan.s
+++ b/src/math/i386/atan.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global atan
 .type atan,@function
 atan:
+	ENDBRANCH32
 	fldl 4(%esp)
 	mov 8(%esp),%eax
 	add %eax,%eax
diff --git a/src/math/i386/atan2.s b/src/math/i386/atan2.s
index 8bc441b1..fc8ac07a 100644
--- a/src/math/i386/atan2.s
+++ b/src/math/i386/atan2.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global atan2
 .type atan2,@function
 atan2:
+	ENDBRANCH32
 	fldl 4(%esp)
 	fldl 12(%esp)
 	fpatan
diff --git a/src/math/i386/atan2f.s b/src/math/i386/atan2f.s
index 3908c86d..6e52276a 100644
--- a/src/math/i386/atan2f.s
+++ b/src/math/i386/atan2f.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global atan2f
 .type atan2f,@function
 atan2f:
+	ENDBRANCH32
 	flds 4(%esp)
 	flds 8(%esp)
 	fpatan
diff --git a/src/math/i386/atan2l.s b/src/math/i386/atan2l.s
index adf6e10a..34640836 100644
--- a/src/math/i386/atan2l.s
+++ b/src/math/i386/atan2l.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global atan2l
 .type atan2l,@function
 atan2l:
+	ENDBRANCH32
 	fldt 4(%esp)
 	fldt 16(%esp)
 	fpatan
diff --git a/src/math/i386/atanf.s b/src/math/i386/atanf.s
index c2cbe2e0..a9064b2c 100644
--- a/src/math/i386/atanf.s
+++ b/src/math/i386/atanf.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global atanf
 .type atanf,@function
 atanf:
+	ENDBRANCH32
 	flds 4(%esp)
 	mov 4(%esp),%eax
 	add %eax,%eax
diff --git a/src/math/i386/atanl.s b/src/math/i386/atanl.s
index c508bc46..4200304f 100644
--- a/src/math/i386/atanl.s
+++ b/src/math/i386/atanl.s
@@ -1,6 +1,8 @@
+.include "ibt.s"
 .global atanl
 .type atanl,@function
 atanl:
+	ENDBRANCH32
 	fldt 4(%esp)
 	fld1
 	fpatan
diff --git a/src/math/i386/exp_ld.s b/src/math/i386/exp_ld.s
index 99cba01f..93256fac 100644
--- a/src/math/i386/exp_ld.s
+++ b/src/math/i386/exp_ld.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global expm1l
 .type expm1l,@function
 expm1l:
+	ENDBRANCH32
 	fldt 4(%esp)
 	fldl2e
 	fmulp
@@ -38,6 +41,7 @@ expm1l:
 .type exp2l,@function
 exp2l:
 __exp2l:
+	ENDBRANCH32
 	fldt 4(%esp)
 1:	sub $12,%esp
 	fld %st(0)
diff --git a/src/math/i386/expl.s b/src/math/i386/expl.s
index b5124e8f..6e6b8814 100644
--- a/src/math/i386/expl.s
+++ b/src/math/i386/expl.s
@@ -1,3 +1,4 @@
+.include "ibt.s"
 # exp(x) = 2^hi + 2^hi (2^lo - 1)
 # where hi+lo = log2e*x with 128bit precision
 # exact log2e*x calculation depends on nearest rounding mode
@@ -6,6 +7,7 @@
 .global expl
 .type expl,@function
 expl:
+	ENDBRANCH32
 	fldt 4(%esp)
 
 		# interesting case: 0x1p-32 <= |x| < 16384
diff --git a/src/math/i386/floor.s b/src/math/i386/floor.s
index 46ba88db..d5360a95 100644
--- a/src/math/i386/floor.s
+++ b/src/math/i386/floor.s
@@ -1,18 +1,23 @@
+.include "ibt.s"
+
 .global floorf
 .type floorf,@function
 floorf:
+	ENDBRANCH32
 	flds 4(%esp)
 	jmp 1f
 
 .global floorl
 .type floorl,@function
 floorl:
+	ENDBRANCH32
 	fldt 4(%esp)
 	jmp 1f
 
 .global floor
 .type floor,@function
 floor:
+	ENDBRANCH32
 	fldl 4(%esp)
 1:	mov $0x7,%al
 1:	fstcw 4(%esp)
@@ -27,6 +32,7 @@ floor:
 .global ceil
 .type ceil,@function
 ceil:
+	ENDBRANCH32
 	fldl 4(%esp)
 	mov $0xb,%al
 	jmp 1b
@@ -34,6 +40,7 @@ ceil:
 .global ceilf
 .type ceilf,@function
 ceilf:
+	ENDBRANCH32
 	flds 4(%esp)
 	mov $0xb,%al
 	jmp 1b
@@ -41,6 +48,7 @@ ceilf:
 .global ceill
 .type ceill,@function
 ceill:
+	ENDBRANCH32
 	fldt 4(%esp)
 	mov $0xb,%al
 	jmp 1b
@@ -48,6 +56,7 @@ ceill:
 .global trunc
 .type trunc,@function
 trunc:
+	ENDBRANCH32
 	fldl 4(%esp)
 	mov $0xf,%al
 	jmp 1b
@@ -55,6 +64,7 @@ trunc:
 .global truncf
 .type truncf,@function
 truncf:
+	ENDBRANCH32
 	flds 4(%esp)
 	mov $0xf,%al
 	jmp 1b
@@ -62,6 +72,7 @@ truncf:
 .global truncl
 .type truncl,@function
 truncl:
+	ENDBRANCH32
 	fldt 4(%esp)
 	mov $0xf,%al
 	jmp 1b
diff --git a/src/math/i386/hypot.s b/src/math/i386/hypot.s
index 299c2e18..c7859075 100644
--- a/src/math/i386/hypot.s
+++ b/src/math/i386/hypot.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global hypot
 .type hypot,@function
 hypot:
+	ENDBRANCH32
 	mov 8(%esp),%eax
 	mov 16(%esp),%ecx
 	add %eax,%eax
diff --git a/src/math/i386/hypotf.s b/src/math/i386/hypotf.s
index 068935e2..bf3162d7 100644
--- a/src/math/i386/hypotf.s
+++ b/src/math/i386/hypotf.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global hypotf
 .type hypotf,@function
 hypotf:
+	ENDBRANCH32
 	mov 4(%esp),%eax
 	mov 8(%esp),%ecx
 	add %eax,%eax
diff --git a/src/math/i386/log.s b/src/math/i386/log.s
index 08c59924..fadd46e8 100644
--- a/src/math/i386/log.s
+++ b/src/math/i386/log.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log
 .type log,@function
 log:
+	ENDBRANCH32
 	fldln2
 	fldl 4(%esp)
 	fyl2x
diff --git a/src/math/i386/log10.s b/src/math/i386/log10.s
index 120e91ec..3facf5fc 100644
--- a/src/math/i386/log10.s
+++ b/src/math/i386/log10.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log10
 .type log10,@function
 log10:
+	ENDBRANCH32
 	fldlg2
 	fldl 4(%esp)
 	fyl2x
diff --git a/src/math/i386/log10f.s b/src/math/i386/log10f.s
index b055493a..70b0c447 100644
--- a/src/math/i386/log10f.s
+++ b/src/math/i386/log10f.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log10f
 .type log10f,@function
 log10f:
+	ENDBRANCH32
 	fldlg2
 	flds 4(%esp)
 	fyl2x
diff --git a/src/math/i386/log10l.s b/src/math/i386/log10l.s
index aaa44f2f..663227fd 100644
--- a/src/math/i386/log10l.s
+++ b/src/math/i386/log10l.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log10l
 .type log10l,@function
 log10l:
+	ENDBRANCH32
 	fldlg2
 	fldt 4(%esp)
 	fyl2x
diff --git a/src/math/i386/log1p.s b/src/math/i386/log1p.s
index f3c95f83..681bda68 100644
--- a/src/math/i386/log1p.s
+++ b/src/math/i386/log1p.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log1p
 .type log1p,@function
 log1p:
+	ENDBRANCH32
 	mov 8(%esp),%eax
 	fldln2
 	and $0x7fffffff,%eax
diff --git a/src/math/i386/log1pf.s b/src/math/i386/log1pf.s
index 9f13d95f..7bc9f87e 100644
--- a/src/math/i386/log1pf.s
+++ b/src/math/i386/log1pf.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log1pf
 .type log1pf,@function
 log1pf:
+	ENDBRANCH32
 	mov 4(%esp),%eax
 	fldln2
 	and $0x7fffffff,%eax
diff --git a/src/math/i386/log1pl.s b/src/math/i386/log1pl.s
index a048ab6b..5e549af6 100644
--- a/src/math/i386/log1pl.s
+++ b/src/math/i386/log1pl.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log1pl
 .type log1pl,@function
 log1pl:
+	ENDBRANCH32
 	mov 10(%esp),%eax
 	fldln2
 	and $0x7fffffff,%eax
diff --git a/src/math/i386/log2.s b/src/math/i386/log2.s
index 7eff0b61..c50525bd 100644
--- a/src/math/i386/log2.s
+++ b/src/math/i386/log2.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log2
 .type log2,@function
 log2:
+	ENDBRANCH32
 	fld1
 	fldl 4(%esp)
 	fyl2x
diff --git a/src/math/i386/log2f.s b/src/math/i386/log2f.s
index b32fa2f7..06cf0063 100644
--- a/src/math/i386/log2f.s
+++ b/src/math/i386/log2f.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log2f
 .type log2f,@function
 log2f:
+	ENDBRANCH32
 	fld1
 	flds 4(%esp)
 	fyl2x
diff --git a/src/math/i386/log2l.s b/src/math/i386/log2l.s
index c58f56fd..6d9d5217 100644
--- a/src/math/i386/log2l.s
+++ b/src/math/i386/log2l.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global log2l
 .type log2l,@function
 log2l:
+	ENDBRANCH32
 	fld1
 	fldt 4(%esp)
 	fyl2x
diff --git a/src/math/i386/logf.s b/src/math/i386/logf.s
index 4d0346a4..e846d3f6 100644
--- a/src/math/i386/logf.s
+++ b/src/math/i386/logf.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global logf
 .type logf,@function
 logf:
+	ENDBRANCH32
 	fldln2
 	flds 4(%esp)
 	fyl2x
diff --git a/src/math/i386/logl.s b/src/math/i386/logl.s
index d4e3339b..1cb52139 100644
--- a/src/math/i386/logl.s
+++ b/src/math/i386/logl.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global logl
 .type logl,@function
 logl:
+	ENDBRANCH32
 	fldln2
 	fldt 4(%esp)
 	fyl2x
diff --git a/src/math/i386/remquo.s b/src/math/i386/remquo.s
index 598e7549..6bb69298 100644
--- a/src/math/i386/remquo.s
+++ b/src/math/i386/remquo.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global remquof
 .type remquof,@function
 remquof:
+	ENDBRANCH32
 	mov 12(%esp),%ecx
 	flds 8(%esp)
 	flds 4(%esp)
@@ -11,6 +14,7 @@ remquof:
 .global remquol
 .type remquol,@function
 remquol:
+	ENDBRANCH32
 	mov 28(%esp),%ecx
 	fldt 16(%esp)
 	fldt 4(%esp)
@@ -21,6 +25,7 @@ remquol:
 .global remquo
 .type remquo,@function
 remquo:
+	ENDBRANCH32
 	mov 20(%esp),%ecx
 	fldl 12(%esp)
 	fldl 4(%esp)
diff --git a/src/math/i386/scalbn.s b/src/math/i386/scalbn.s
index 8bf302f2..188f2ede 100644
--- a/src/math/i386/scalbn.s
+++ b/src/math/i386/scalbn.s
@@ -1,16 +1,21 @@
+.include "ibt.s"
+
 .global ldexp
 .type ldexp,@function
 ldexp:
+	ENDBRANCH32
 	nop
 
 .global scalbln
 .type scalbln,@function
 scalbln:
+	ENDBRANCH32
 	nop
 
 .global scalbn
 .type scalbn,@function
 scalbn:
+	ENDBRANCH32
 	mov 12(%esp),%eax
 	add $0x3ffe,%eax
 	cmp $0x7ffd,%eax
diff --git a/src/math/i386/scalbnf.s b/src/math/i386/scalbnf.s
index 9cb9ef5f..5d23bbe1 100644
--- a/src/math/i386/scalbnf.s
+++ b/src/math/i386/scalbnf.s
@@ -1,16 +1,21 @@
+.include "ibt.s"
+
 .global ldexpf
 .type ldexpf,@function
 ldexpf:
+	ENDBRANCH32
 	nop
 
 .global scalblnf
 .type scalblnf,@function
 scalblnf:
+	ENDBRANCH32
 	nop
 
 .global scalbnf
 .type scalbnf,@function
 scalbnf:
+	ENDBRANCH32
 	mov 8(%esp),%eax
 	add $0x3fe,%eax
 	cmp $0x7fd,%eax
diff --git a/src/math/i386/scalbnl.s b/src/math/i386/scalbnl.s
index 54414c2e..5f1d78de 100644
--- a/src/math/i386/scalbnl.s
+++ b/src/math/i386/scalbnl.s
@@ -1,16 +1,21 @@
+.include "ibt.s"
+
 .global ldexpl
 .type ldexpl,@function
 ldexpl:
+	ENDBRANCH32
 	nop
 
 .global scalblnl
 .type scalblnl,@function
 scalblnl:
+	ENDBRANCH32
 	nop
 
 .global scalbnl
 .type scalbnl,@function
 scalbnl:
+	ENDBRANCH32
 	mov 16(%esp),%eax
 	add $0x3ffe,%eax
 	cmp $0x7ffd,%eax
diff --git a/src/process/i386/vfork.s b/src/process/i386/vfork.s
index 3d0e6d6b..a055623a 100644
--- a/src/process/i386/vfork.s
+++ b/src/process/i386/vfork.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global vfork
 .type vfork,@function
 vfork:
+	ENDBRANCH32
 	pop %edx
 	mov $190,%eax
 	int $128
diff --git a/src/setjmp/i386/longjmp.s b/src/setjmp/i386/longjmp.s
index 8188f06b..f0b54db4 100644
--- a/src/setjmp/i386/longjmp.s
+++ b/src/setjmp/i386/longjmp.s
@@ -1,9 +1,12 @@
+.include "ibt.s"
+
 .global _longjmp
 .global longjmp
 .type _longjmp,@function
 .type longjmp,@function
 _longjmp:
 longjmp:
+	ENDBRANCH32
 	mov  4(%esp),%edx
 	mov  8(%esp),%eax
 	cmp       $1,%eax
diff --git a/src/setjmp/i386/setjmp.s b/src/setjmp/i386/setjmp.s
index 4d19cf87..76cd58be 100644
--- a/src/setjmp/i386/setjmp.s
+++ b/src/setjmp/i386/setjmp.s
@@ -1,3 +1,5 @@
+.include "ibt.s"
+
 .global ___setjmp
 .hidden ___setjmp
 .global __setjmp
@@ -10,6 +12,7 @@ ___setjmp:
 __setjmp:
 _setjmp:
 setjmp:
+	ENDBRANCH32
 	mov 4(%esp), %eax
 	mov    %ebx, (%eax)
 	mov    %esi, 4(%eax)
diff --git a/src/signal/i386/restore.s b/src/signal/i386/restore.s
index ccc94307..6f668b9a 100644
--- a/src/signal/i386/restore.s
+++ b/src/signal/i386/restore.s
@@ -1,7 +1,10 @@
+.include "ibt.s"
+
 .global __restore
 .hidden __restore
 .type __restore,@function
 __restore:
+	ENDBRANCH32
 	popl %eax
 	movl $119, %eax
 	int $0x80
@@ -10,5 +13,6 @@ __restore:
 .hidden __restore_rt
 .type __restore_rt,@function
 __restore_rt:
+	ENDBRANCH32
 	movl $173, %eax
 	int $0x80
diff --git a/src/signal/i386/sigsetjmp.s b/src/signal/i386/sigsetjmp.s
index 690b251c..ed69432c 100644
--- a/src/signal/i386/sigsetjmp.s
+++ b/src/signal/i386/sigsetjmp.s
@@ -1,9 +1,12 @@
+.include "ibt.s"
+
 .global sigsetjmp
 .global __sigsetjmp
 .type sigsetjmp,@function
 .type __sigsetjmp,@function
 sigsetjmp:
 __sigsetjmp:
+	ENDBRANCH32
 	mov 8(%esp),%ecx
 	jecxz 1f
 
diff --git a/src/string/i386/memcpy.s b/src/string/i386/memcpy.s
index 0608dd83..9650d880 100644
--- a/src/string/i386/memcpy.s
+++ b/src/string/i386/memcpy.s
@@ -1,8 +1,11 @@
+.include "ibt.s"
+
 .global memcpy
 .global __memcpy_fwd
 .hidden __memcpy_fwd
 .type memcpy,@function
 memcpy:
+	ENDBRANCH32
 __memcpy_fwd:
 	push %esi
 	push %edi
diff --git a/src/string/i386/memmove.s b/src/string/i386/memmove.s
index 2a6a504b..36dfd2c9 100644
--- a/src/string/i386/memmove.s
+++ b/src/string/i386/memmove.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global memmove
 .type memmove,@function
 memmove:
+	ENDBRANCH32
 	mov 4(%esp),%eax
 	sub 8(%esp),%eax
 	cmp 12(%esp),%eax
diff --git a/src/string/i386/memset.s b/src/string/i386/memset.s
index d00422c4..3067fc63 100644
--- a/src/string/i386/memset.s
+++ b/src/string/i386/memset.s
@@ -1,6 +1,9 @@
+.include "ibt.s"
+
 .global memset
 .type memset,@function
 memset:
+	ENDBRANCH32
 	mov 12(%esp),%ecx
 	cmp $62,%ecx
 	ja 2f
@@ -47,7 +50,7 @@ memset:
 	mov %edx,(-1-2-4-8-8)(%eax,%ecx)
 	mov %edx,(-1-2-4-8-4)(%eax,%ecx)
 
-1:	ret 	
+1:	ret
 
 2:	movzbl 8(%esp),%eax
 	mov %edi,12(%esp)
@@ -63,7 +66,7 @@ memset:
 	mov 4(%esp),%eax
 	mov 12(%esp),%edi
 	ret
-	
+
 2:	xor %edx,%edx
 	sub %edi,%edx
 	and $15,%edx
diff --git a/src/thread/i386/__set_thread_area.s b/src/thread/i386/__set_thread_area.s
index aa6852be..5bddb956 100644
--- a/src/thread/i386/__set_thread_area.s
+++ b/src/thread/i386/__set_thread_area.s
@@ -1,8 +1,11 @@
+.include "ibt.s"
+
 .text
 .global __set_thread_area
 .hidden __set_thread_area
 .type   __set_thread_area,@function
 __set_thread_area:
+	ENDBRANCH32
 	push %ebx
 	push $0x51
 	push $0xfffff
diff --git a/src/thread/i386/__unmapself.s b/src/thread/i386/__unmapself.s
index d6569594..0b1feb2e 100644
--- a/src/thread/i386/__unmapself.s
+++ b/src/thread/i386/__unmapself.s
@@ -1,7 +1,10 @@
+.include "ibt.s"
+
 .text
 .global __unmapself
 .type   __unmapself,@function
 __unmapself:
+	ENDBRANCH32
 	movl $91,%eax
 	movl 4(%esp),%ebx
 	movl 8(%esp),%ecx
diff --git a/src/thread/i386/clone.s b/src/thread/i386/clone.s
index e237d3c6..79050643 100644
--- a/src/thread/i386/clone.s
+++ b/src/thread/i386/clone.s
@@ -1,8 +1,11 @@
+.include "ibt.s"
+
 .text
 .global __clone
 .hidden __clone
 .type   __clone,@function
 __clone:
+	ENDBRANCH32
 	push %ebp
 	mov %esp,%ebp
 	push %ebx
diff --git a/src/thread/i386/syscall_cp.s b/src/thread/i386/syscall_cp.s
index 7dce1eb3..7a5f0f98 100644
--- a/src/thread/i386/syscall_cp.s
+++ b/src/thread/i386/syscall_cp.s
@@ -1,3 +1,5 @@
+.include "ibt.s"
+
 .text
 .global __cp_begin
 .hidden __cp_begin
@@ -10,6 +12,7 @@
 .hidden __syscall_cp_asm
 .type   __syscall_cp_asm,@function
 __syscall_cp_asm:
+	ENDBRANCH32
 	mov 4(%esp),%ecx
 	pushl %ebx
 	pushl %esi
diff --git a/src/thread/i386/tls.s b/src/thread/i386/tls.s
index 6e4c4cb9..fdd2278a 100644
--- a/src/thread/i386/tls.s
+++ b/src/thread/i386/tls.s
@@ -1,7 +1,10 @@
+.include "ibt.s"
+
 .text
 .global ___tls_get_addr
 .type ___tls_get_addr,@function
 ___tls_get_addr:
+	ENDBRANCH32
 	mov %gs:4,%edx
 	mov (%eax),%ecx
 	mov 4(%eax),%eax
-- 
2.27.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-19 22:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-19 22:43 [musl] [PATCH 0/4] Add CET IBT Support to MUSL Joao Moreira
2020-10-19 22:43 ` [musl] [PATCH 1/4] Support ASFLAGS in configure and Makefile Joao Moreira
2020-10-19 22:43 ` [musl] [PATCH 2/4] Add ENDBRANCH64 and ENDBRANCH32 macro definitions Joao Moreira
2020-10-19 22:43 ` [musl] [PATCH 3/4] Add endbr64 to x86_64 assembly functions Joao Moreira
2020-10-19 22:43 ` [musl] [PATCH 4/4] Add endbr32 to i386 " Joao Moreira

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).