public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] libphobos: fix CET for non-glibc targets
       [not found] <20211220000831.332831-1-alex_y_xu.ref@yahoo.ca>
@ 2021-12-20  0:08 ` Alex Xu (Hello71)
  2021-12-20  0:08   ` [PATCH 2/2] libphobos: don't compile empty switchcontext.S Alex Xu (Hello71)
  2021-12-20 13:56   ` [PATCH 1/2] libphobos: fix CET for non-glibc targets ibuclaw
  0 siblings, 2 replies; 6+ messages in thread
From: Alex Xu (Hello71) @ 2021-12-20  0:08 UTC (permalink / raw)
  To: gcc-patches; +Cc: Alex Xu (Hello71)

On musl, linking against libphobos fails because it requires ucontext
but is not explicitly linked against it. This is caused by configure
assuming that it is implemented in assembly, but it is actually not
implemented. This silently works on other libcs because context API does
not require an external library.
---
 libphobos/m4/druntime/libraries.m4 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libphobos/m4/druntime/libraries.m4 b/libphobos/m4/druntime/libraries.m4
index 45a56f6f76a..e11582e433a 100644
--- a/libphobos/m4/druntime/libraries.m4
+++ b/libphobos/m4/druntime/libraries.m4
@@ -223,10 +223,14 @@ AC_DEFUN([DRUNTIME_LIBRARIES_UCONTEXT],
   case "$target_cpu" in
     aarch64* | \
     arm* | \
-    i[[34567]]86|x86_64 | \
     powerpc)
       druntime_fiber_asm_external=yes
       ;;
+    i[[34567]]86|x86_64)
+      if test "$enable_cet" = no; then
+        druntime_fiber_asm_external=yes
+      fi
+      ;;
   esac
   if test "$druntime_fiber_asm_external" = no; then
     AC_SEARCH_LIBS([swapcontext], [c ucontext], [],
-- 
2.34.1


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

* [PATCH 2/2] libphobos: don't compile empty switchcontext.S
  2021-12-20  0:08 ` [PATCH 1/2] libphobos: fix CET for non-glibc targets Alex Xu (Hello71)
@ 2021-12-20  0:08   ` Alex Xu (Hello71)
  2021-12-20 13:56   ` [PATCH 1/2] libphobos: fix CET for non-glibc targets ibuclaw
  1 sibling, 0 replies; 6+ messages in thread
From: Alex Xu (Hello71) @ 2021-12-20  0:08 UTC (permalink / raw)
  To: gcc-patches; +Cc: Alex Xu (Hello71)

If it does not contain any files, then there is no point compiling it.
Skipping this saves some milliseconds and ~650 bytes in libgphobos.a.
---
 libphobos/configure.ac                        |  1 +
 libphobos/libdruntime/Makefile.am             |  2 ++
 .../libdruntime/config/x86/switchcontext.S    | 25 ++++++-------------
 3 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/libphobos/configure.ac b/libphobos/configure.ac
index c961e68105a..7169f016ffe 100644
--- a/libphobos/configure.ac
+++ b/libphobos/configure.ac
@@ -78,6 +78,7 @@ AS_IF([test x$enable_cet = xyes], [
 ])
 AC_SUBST(CET_DFLAGS)
 AC_SUBST(DCFG_ENABLE_CET)
+AM_CONDITIONAL([ENABLE_CET], [test x$enable_cet = xyes])
 
 # This should be inherited in the recursive make, but ensure it is defined.
 test "$AR" || AR=ar
diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am
index 224d06e78ca..77d7934e705 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -93,9 +93,11 @@ if DRUNTIME_CPU_X86
 if DRUNTIME_OS_MINGW
     DRUNTIME_SOURCES_CONFIGURED += config/mingw/switchcontext.S
 else
+if !ENABLE_CET
     DRUNTIME_SOURCES_CONFIGURED += config/x86/switchcontext.S
 endif
 endif
+endif
 if DRUNTIME_CPU_SYSTEMZ
     DRUNTIME_SOURCES_CONFIGURED += config/systemz/get_tls_offset.S
 endif
diff --git a/libphobos/libdruntime/config/x86/switchcontext.S b/libphobos/libdruntime/config/x86/switchcontext.S
index 9f4befdb49c..adc46a3b89d 100644
--- a/libphobos/libdruntime/config/x86/switchcontext.S
+++ b/libphobos/libdruntime/config/x86/switchcontext.S
@@ -24,16 +24,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include "../common/threadasm.S"
 
-/* NB: Generate the CET marker for -fcf-protection.  */
-#ifdef __CET__
-# include <cet.h>
-#endif
+#if defined(__ELF__)
 
-#if !defined(__CET__)
-
-# if defined(__ELF__)
-
-#  if defined(__i386__)
+# if defined(__i386__)
 
     .text
     .globl CSYM(fiber_switchContext)
@@ -104,13 +97,13 @@ CSYM(fiber_switchContext):
     .cfi_endproc
    .size CSYM(fiber_switchContext),.-CSYM(fiber_switchContext)
 
-#  endif /* defined(__ELF__) && defined(__x86_64__) && !defined(__ILP32__) */
+# endif /* defined(__ELF__) && defined(__x86_64__) && !defined(__ILP32__) */
 
-# endif /* defined(__ELF__) */
+#endif /* defined(__ELF__) */
 
-# if defined(__MACH__)
+#if defined(__MACH__)
 
-#  if defined(__i386__)
+# if defined(__i386__)
 
     .text
     .globl CSYM(fiber_switchContext)
@@ -247,8 +240,6 @@ LASFDE1:
         .p2align 3,0
 LEFDE1:
 
-#  endif /* defined(__MACH__) && defined(__x86_64__) && !defined(__ILP32__) */
+# endif /* defined(__MACH__) && defined(__x86_64__) && !defined(__ILP32__) */
 
-# endif /* defined (__MACH__) */
-
-#endif /* !defined(__CET__) */
+#endif /* defined (__MACH__) */
-- 
2.34.1


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

* Re: [PATCH 1/2] libphobos: fix CET for non-glibc targets
  2021-12-20  0:08 ` [PATCH 1/2] libphobos: fix CET for non-glibc targets Alex Xu (Hello71)
  2021-12-20  0:08   ` [PATCH 2/2] libphobos: don't compile empty switchcontext.S Alex Xu (Hello71)
@ 2021-12-20 13:56   ` ibuclaw
  2021-12-20 15:41     ` Alex Xu (Hello71)
  1 sibling, 1 reply; 6+ messages in thread
From: ibuclaw @ 2021-12-20 13:56 UTC (permalink / raw)
  To: Alex Xu (Hello71), Alex Xu (Hello71) via Gcc-patches

> On 20/12/2021 01:08 Alex Xu (Hello71) via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> 
>  
> On musl, linking against libphobos fails because it requires ucontext
> but is not explicitly linked against it. This is caused by configure
> assuming that it is implemented in assembly, but it is actually not
> implemented. This silently works on other libcs because context API does
> not require an external library.

Thanks.

Looks reasonable to me, also for backporting to gcc-11, which also has the same CET support.

Iain.

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

* Re: [PATCH 1/2] libphobos: fix CET for non-glibc targets
  2021-12-20 13:56   ` [PATCH 1/2] libphobos: fix CET for non-glibc targets ibuclaw
@ 2021-12-20 15:41     ` Alex Xu (Hello71)
  2021-12-20 21:00       ` ibuclaw
  0 siblings, 1 reply; 6+ messages in thread
From: Alex Xu (Hello71) @ 2021-12-20 15:41 UTC (permalink / raw)
  To: Alex Xu (Hello71) via Gcc-patches, ibuclaw

Excerpts from ibuclaw@gdcproject.org's message of December 20, 2021 8:56 am:
>> On 20/12/2021 01:08 Alex Xu (Hello71) via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>> 
>>  
>> On musl, linking against libphobos fails because it requires ucontext
>> but is not explicitly linked against it. This is caused by configure
>> assuming that it is implemented in assembly, but it is actually not
>> implemented. This silently works on other libcs because context API does
>> not require an external library.
> 
> Thanks.
> 
> Looks reasonable to me, also for backporting to gcc-11, which also has the same CET support.
> 
> Iain.
> 

Yes, we noticed this first on gcc 11. I tested that these patches fix 
the issue on gcc 11, and since nothing seems to have changed, I think 
the same problem exists and will be fixed by these patches on master.

Cheers,
Alex.

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

* Re: [PATCH 1/2] libphobos: fix CET for non-glibc targets
  2021-12-20 15:41     ` Alex Xu (Hello71)
@ 2021-12-20 21:00       ` ibuclaw
  2021-12-28 14:18         ` Alex Xu (Hello71)
  0 siblings, 1 reply; 6+ messages in thread
From: ibuclaw @ 2021-12-20 21:00 UTC (permalink / raw)
  To: Alex Xu (Hello71), Alex Xu (Hello71) via Gcc-patches

> On 20/12/2021 16:41 Alex Xu (Hello71) <alex_y_xu@yahoo.ca> wrote:
> 
>  
> Excerpts from ibuclaw@gdcproject.org's message of December 20, 2021 8:56 am:
> >> On 20/12/2021 01:08 Alex Xu (Hello71) via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> >> 
> >>  
> >> On musl, linking against libphobos fails because it requires ucontext
> >> but is not explicitly linked against it. This is caused by configure
> >> assuming that it is implemented in assembly, but it is actually not
> >> implemented. This silently works on other libcs because context API does
> >> not require an external library.
> > 
> > Thanks.
> > 
> > Looks reasonable to me, also for backporting to gcc-11, which also has the same CET support.
> > 
> > Iain.
> > 
> 
> Yes, we noticed this first on gcc 11. I tested that these patches fix 
> the issue on gcc 11, and since nothing seems to have changed, I think 
> the same problem exists and will be fixed by these patches on master.
> 

Do you need me to commit this?

Iain.

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

* Re: [PATCH 1/2] libphobos: fix CET for non-glibc targets
  2021-12-20 21:00       ` ibuclaw
@ 2021-12-28 14:18         ` Alex Xu (Hello71)
  0 siblings, 0 replies; 6+ messages in thread
From: Alex Xu (Hello71) @ 2021-12-28 14:18 UTC (permalink / raw)
  To: Alex Xu (Hello71) via Gcc-patches, ibuclaw

Excerpts from ibuclaw@gdcproject.org's message of December 20, 2021 4:00 pm:
>> On 20/12/2021 16:41 Alex Xu (Hello71) <alex_y_xu@yahoo.ca> wrote:
>> 
>>  
>> Excerpts from ibuclaw@gdcproject.org's message of December 20, 2021 8:56 am:
>> >> On 20/12/2021 01:08 Alex Xu (Hello71) via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>> >> 
>> >>  
>> >> On musl, linking against libphobos fails because it requires ucontext
>> >> but is not explicitly linked against it. This is caused by configure
>> >> assuming that it is implemented in assembly, but it is actually not
>> >> implemented. This silently works on other libcs because context API does
>> >> not require an external library.
>> > 
>> > Thanks.
>> > 
>> > Looks reasonable to me, also for backporting to gcc-11, which also has the same CET support.
>> > 
>> > Iain.
>> > 
>> 
>> Yes, we noticed this first on gcc 11. I tested that these patches fix 
>> the issue on gcc 11, and since nothing seems to have changed, I think 
>> the same problem exists and will be fixed by these patches on master.
>> 
> 
> Do you need me to commit this?
> 
> Iain.
> 

I wrote this patch for Alpine Linux and have submitted it for review 
and, since I do not have commit access to gcc, in the hope that someone 
can commit it so that non-Alpine users may benefit and also Alpine will 
not have to maintain the patch. Since I am not familiar with gcc 
development procedures, I don't know if that means I need something from 
you specifically, but if somebody could commit it, that would be 
appreciated.

Also, since I forgot to do so initially, please apply Signed-off-by: 
Alex Xu (Hello71) <alex_y_xu@yahoo.ca>.

Cheers,
Alex.

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

end of thread, other threads:[~2021-12-28 14:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20211220000831.332831-1-alex_y_xu.ref@yahoo.ca>
2021-12-20  0:08 ` [PATCH 1/2] libphobos: fix CET for non-glibc targets Alex Xu (Hello71)
2021-12-20  0:08   ` [PATCH 2/2] libphobos: don't compile empty switchcontext.S Alex Xu (Hello71)
2021-12-20 13:56   ` [PATCH 1/2] libphobos: fix CET for non-glibc targets ibuclaw
2021-12-20 15:41     ` Alex Xu (Hello71)
2021-12-20 21:00       ` ibuclaw
2021-12-28 14:18         ` Alex Xu (Hello71)

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 read-only IMAP folder(s) and NNTP newsgroup(s).