public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/2] StdLib/LibC: avoid LTO code for compiler intrinsics
@ 2016-08-08 11:12 Ard Biesheuvel
  2016-08-08 11:12 ` [PATCH 2/2] StdLib/LibC ARM AARCH64: do not redefine " Ard Biesheuvel
  2016-08-08 11:24 ` [PATCH 1/2] StdLib/LibC: avoid LTO code for " Michael Zimmermann
  0 siblings, 2 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2016-08-08 11:12 UTC (permalink / raw)
  To: edk2-devel, edk2-lists, jaben.carsey
  Cc: sigmaepsilon92, leif.lindholm, Ard Biesheuvel

The softfloat routines and some other routines supplied by LibC
will satisfy references to compiler intrinsics that are emitted
by the compiler backend, which under LTO means that the link-time
code generation may emit references to symbols that have been
optimized away already.

Work around this by building the ARM and AARCH64 versions of LibC
and the softfloat library without LTO.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 StdLib/LibC/LibC.inf                | 1 +
 StdLib/LibC/Softfloat/Softfloat.inf | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/StdLib/LibC/LibC.inf b/StdLib/LibC/LibC.inf
index f13630648555..6039bb81c7dd 100644
--- a/StdLib/LibC/LibC.inf
+++ b/StdLib/LibC/LibC.inf
@@ -120,3 +120,4 @@ [LibraryClasses]
 #
 [BuildOptions]
   MSFT:*_*_IA32_CC_FLAGS = /GL-
+  GCC:*_*_ARM_CC_FLAGS = -fno-lto
diff --git a/StdLib/LibC/Softfloat/Softfloat.inf b/StdLib/LibC/Softfloat/Softfloat.inf
index 99763bcb57ba..460406c38fa4 100644
--- a/StdLib/LibC/Softfloat/Softfloat.inf
+++ b/StdLib/LibC/Softfloat/Softfloat.inf
@@ -71,4 +71,4 @@ [Packages]
 # Nasty things could happen if you do.
 
 [BuildOptions]
-  GCC:*_*_*_CC_FLAGS  = -DSOFTFLOAT_FOR_GCC -Wno-enum-compare -fno-tree-vrp
+  GCC:*_*_*_CC_FLAGS  = -DSOFTFLOAT_FOR_GCC -Wno-enum-compare -fno-tree-vrp -fno-lto
-- 
2.7.4



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

* [PATCH 2/2] StdLib/LibC ARM AARCH64: do not redefine compiler intrinsics
  2016-08-08 11:12 [PATCH 1/2] StdLib/LibC: avoid LTO code for compiler intrinsics Ard Biesheuvel
@ 2016-08-08 11:12 ` Ard Biesheuvel
  2016-08-08 14:56   ` Carsey, Jaben
  2016-08-08 11:24 ` [PATCH 1/2] StdLib/LibC: avoid LTO code for " Michael Zimmermann
  1 sibling, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2016-08-08 11:12 UTC (permalink / raw)
  To: edk2-devel, edk2-lists, jaben.carsey
  Cc: sigmaepsilon92, leif.lindholm, Ard Biesheuvel

The memset() function is a compiler intrinsics on AARCH64 and ARM, and
so is memmove() on ARM. Usually, redefining them as LibC currently does
is not a problem since only one version will be selected at link time
from the various static libraries that provide implementations. However,
under LTO, this is slightly different, since explicit references (in the
C code) and implicit references (emitted by the compiler backend) may
resolve to different versions (LTO vs non-LTO), causing conflicts.

So simply omit them for ARM/AARCH64 resp. ARM.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 StdLib/LibC/String/Copying.c | 2 ++
 StdLib/LibC/String/Misc.c    | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/StdLib/LibC/String/Copying.c b/StdLib/LibC/String/Copying.c
index 96be24b9a9bd..3234eccf0808 100644
--- a/StdLib/LibC/String/Copying.c
+++ b/StdLib/LibC/String/Copying.c
@@ -39,6 +39,7 @@ memcpy(void * __restrict s1, const void * __restrict s2, size_t n)
 }
 #endif  /* !(defined(MDE_CPU_IPF) && defined(__GCC)) */
 
+#if !(defined(MDE_CPU_ARM) && defined(__GNUC__))
 /** The memmove function copies n characters from the object pointed to by s2
     into the object pointed to by s1. Copying takes place as if the n
     characters from the object pointed to by s2 are first copied into a
@@ -57,6 +58,7 @@ memmove(void *s1, const void *s2, size_t n)
 {
   return CopyMem( s1, s2, n);
 }
+#endif
 
 /** The strcpy function copies the string pointed to by s2 (including the
     terminating null character) into the array pointed to by s1. If copying
diff --git a/StdLib/LibC/String/Misc.c b/StdLib/LibC/String/Misc.c
index 99328252ed50..f024136446e7 100644
--- a/StdLib/LibC/String/Misc.c
+++ b/StdLib/LibC/String/Misc.c
@@ -26,6 +26,7 @@
 
 extern char *sys_errlist[];
 
+#if !((defined(MDE_CPU_ARM) || defined(MDE_CPU_AARCH64)) && defined(__GNUC__))
 /** The memset function copies the value of c (converted to an unsigned char)
     into each of the first n characters of the object pointed to by s.
 
@@ -36,6 +37,7 @@ memset(void *s, int c, size_t n)
 {
   return SetMem( s, (UINTN)n, (UINT8)c);
 }
+#endif
 
 int
 strerror_r(int errnum, char *buf, size_t buflen)
-- 
2.7.4



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

* Re: [PATCH 1/2] StdLib/LibC: avoid LTO code for compiler intrinsics
  2016-08-08 11:12 [PATCH 1/2] StdLib/LibC: avoid LTO code for compiler intrinsics Ard Biesheuvel
  2016-08-08 11:12 ` [PATCH 2/2] StdLib/LibC ARM AARCH64: do not redefine " Ard Biesheuvel
@ 2016-08-08 11:24 ` Michael Zimmermann
  2016-08-08 14:56   ` Carsey, Jaben
  1 sibling, 1 reply; 6+ messages in thread
From: Michael Zimmermann @ 2016-08-08 11:24 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: edk2-devel@lists.01.org, Daryl McDaniel, Jaben Carsey (Intel),
	Leif Lindholm

Reviewed-by: Michael Zimmermann <sigmaepsilon92@gmail.com>

On Mon, Aug 8, 2016 at 1:12 PM, Ard Biesheuvel <ard.biesheuvel@linaro.org>
wrote:

> The softfloat routines and some other routines supplied by LibC
> will satisfy references to compiler intrinsics that are emitted
> by the compiler backend, which under LTO means that the link-time
> code generation may emit references to symbols that have been
> optimized away already.
>
> Work around this by building the ARM and AARCH64 versions of LibC
> and the softfloat library without LTO.
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  StdLib/LibC/LibC.inf                | 1 +
>  StdLib/LibC/Softfloat/Softfloat.inf | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/StdLib/LibC/LibC.inf b/StdLib/LibC/LibC.inf
> index f13630648555..6039bb81c7dd 100644
> --- a/StdLib/LibC/LibC.inf
> +++ b/StdLib/LibC/LibC.inf
> @@ -120,3 +120,4 @@ [LibraryClasses]
>  #
>  [BuildOptions]
>    MSFT:*_*_IA32_CC_FLAGS = /GL-
> +  GCC:*_*_ARM_CC_FLAGS = -fno-lto
> diff --git a/StdLib/LibC/Softfloat/Softfloat.inf b/StdLib/LibC/Softfloat/
> Softfloat.inf
> index 99763bcb57ba..460406c38fa4 100644
> --- a/StdLib/LibC/Softfloat/Softfloat.inf
> +++ b/StdLib/LibC/Softfloat/Softfloat.inf
> @@ -71,4 +71,4 @@ [Packages]
>  # Nasty things could happen if you do.
>
>  [BuildOptions]
> -  GCC:*_*_*_CC_FLAGS  = -DSOFTFLOAT_FOR_GCC -Wno-enum-compare
> -fno-tree-vrp
> +  GCC:*_*_*_CC_FLAGS  = -DSOFTFLOAT_FOR_GCC -Wno-enum-compare
> -fno-tree-vrp -fno-lto
> --
> 2.7.4
>
>


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

* Re: [PATCH 1/2] StdLib/LibC: avoid LTO code for compiler intrinsics
  2016-08-08 11:24 ` [PATCH 1/2] StdLib/LibC: avoid LTO code for " Michael Zimmermann
@ 2016-08-08 14:56   ` Carsey, Jaben
  2016-08-09  8:13     ` Ard Biesheuvel
  0 siblings, 1 reply; 6+ messages in thread
From: Carsey, Jaben @ 2016-08-08 14:56 UTC (permalink / raw)
  To: Michael Zimmermann, Ard Biesheuvel
  Cc: edk2-devel@lists.01.org, Leif Lindholm, Daryl McDaniel,
	Carsey, Jaben

Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Michael Zimmermann
> Sent: Monday, August 08, 2016 4:24 AM
> To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Cc: Carsey, Jaben <jaben.carsey@intel.com>; edk2-devel@lists.01.org; Leif
> Lindholm <leif.lindholm@linaro.org>; Daryl McDaniel <edk2-
> lists@mc2research.org>
> Subject: Re: [edk2] [PATCH 1/2] StdLib/LibC: avoid LTO code for compiler
> intrinsics
> Importance: High
> 
> Reviewed-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
> 
> On Mon, Aug 8, 2016 at 1:12 PM, Ard Biesheuvel
> <ard.biesheuvel@linaro.org>
> wrote:
> 
> > The softfloat routines and some other routines supplied by LibC
> > will satisfy references to compiler intrinsics that are emitted
> > by the compiler backend, which under LTO means that the link-time
> > code generation may emit references to symbols that have been
> > optimized away already.
> >
> > Work around this by building the ARM and AARCH64 versions of LibC
> > and the softfloat library without LTO.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > ---
> >  StdLib/LibC/LibC.inf                | 1 +
> >  StdLib/LibC/Softfloat/Softfloat.inf | 2 +-
> >  2 files changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/StdLib/LibC/LibC.inf b/StdLib/LibC/LibC.inf
> > index f13630648555..6039bb81c7dd 100644
> > --- a/StdLib/LibC/LibC.inf
> > +++ b/StdLib/LibC/LibC.inf
> > @@ -120,3 +120,4 @@ [LibraryClasses]
> >  #
> >  [BuildOptions]
> >    MSFT:*_*_IA32_CC_FLAGS = /GL-
> > +  GCC:*_*_ARM_CC_FLAGS = -fno-lto
> > diff --git a/StdLib/LibC/Softfloat/Softfloat.inf b/StdLib/LibC/Softfloat/
> > Softfloat.inf
> > index 99763bcb57ba..460406c38fa4 100644
> > --- a/StdLib/LibC/Softfloat/Softfloat.inf
> > +++ b/StdLib/LibC/Softfloat/Softfloat.inf
> > @@ -71,4 +71,4 @@ [Packages]
> >  # Nasty things could happen if you do.
> >
> >  [BuildOptions]
> > -  GCC:*_*_*_CC_FLAGS  = -DSOFTFLOAT_FOR_GCC -Wno-enum-compare
> > -fno-tree-vrp
> > +  GCC:*_*_*_CC_FLAGS  = -DSOFTFLOAT_FOR_GCC -Wno-enum-
> compare
> > -fno-tree-vrp -fno-lto
> > --
> > 2.7.4
> >
> >
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


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

* Re: [PATCH 2/2] StdLib/LibC ARM AARCH64: do not redefine compiler intrinsics
  2016-08-08 11:12 ` [PATCH 2/2] StdLib/LibC ARM AARCH64: do not redefine " Ard Biesheuvel
@ 2016-08-08 14:56   ` Carsey, Jaben
  0 siblings, 0 replies; 6+ messages in thread
From: Carsey, Jaben @ 2016-08-08 14:56 UTC (permalink / raw)
  To: Ard Biesheuvel, edk2-devel@lists.01.org,
	edk2-lists@mc2research.org
  Cc: sigmaepsilon92@gmail.com, leif.lindholm@linaro.org, Carsey, Jaben

Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

> -----Original Message-----
> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> Sent: Monday, August 08, 2016 4:12 AM
> To: edk2-devel@lists.01.org; edk2-lists@mc2research.org; Carsey, Jaben
> <jaben.carsey@intel.com>
> Cc: sigmaepsilon92@gmail.com; leif.lindholm@linaro.org; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>
> Subject: [PATCH 2/2] StdLib/LibC ARM AARCH64: do not redefine compiler
> intrinsics
> Importance: High
> 
> The memset() function is a compiler intrinsics on AARCH64 and ARM, and
> so is memmove() on ARM. Usually, redefining them as LibC currently does
> is not a problem since only one version will be selected at link time
> from the various static libraries that provide implementations. However,
> under LTO, this is slightly different, since explicit references (in the
> C code) and implicit references (emitted by the compiler backend) may
> resolve to different versions (LTO vs non-LTO), causing conflicts.
> 
> So simply omit them for ARM/AARCH64 resp. ARM.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  StdLib/LibC/String/Copying.c | 2 ++
>  StdLib/LibC/String/Misc.c    | 2 ++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/StdLib/LibC/String/Copying.c b/StdLib/LibC/String/Copying.c
> index 96be24b9a9bd..3234eccf0808 100644
> --- a/StdLib/LibC/String/Copying.c
> +++ b/StdLib/LibC/String/Copying.c
> @@ -39,6 +39,7 @@ memcpy(void * __restrict s1, const void * __restrict s2,
> size_t n)
>  }
>  #endif  /* !(defined(MDE_CPU_IPF) && defined(__GCC)) */
> 
> +#if !(defined(MDE_CPU_ARM) && defined(__GNUC__))
>  /** The memmove function copies n characters from the object pointed to
> by s2
>      into the object pointed to by s1. Copying takes place as if the n
>      characters from the object pointed to by s2 are first copied into a
> @@ -57,6 +58,7 @@ memmove(void *s1, const void *s2, size_t n)
>  {
>    return CopyMem( s1, s2, n);
>  }
> +#endif
> 
>  /** The strcpy function copies the string pointed to by s2 (including the
>      terminating null character) into the array pointed to by s1. If copying
> diff --git a/StdLib/LibC/String/Misc.c b/StdLib/LibC/String/Misc.c
> index 99328252ed50..f024136446e7 100644
> --- a/StdLib/LibC/String/Misc.c
> +++ b/StdLib/LibC/String/Misc.c
> @@ -26,6 +26,7 @@
> 
>  extern char *sys_errlist[];
> 
> +#if !((defined(MDE_CPU_ARM) || defined(MDE_CPU_AARCH64)) &&
> defined(__GNUC__))
>  /** The memset function copies the value of c (converted to an unsigned
> char)
>      into each of the first n characters of the object pointed to by s.
> 
> @@ -36,6 +37,7 @@ memset(void *s, int c, size_t n)
>  {
>    return SetMem( s, (UINTN)n, (UINT8)c);
>  }
> +#endif
> 
>  int
>  strerror_r(int errnum, char *buf, size_t buflen)
> --
> 2.7.4



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

* Re: [PATCH 1/2] StdLib/LibC: avoid LTO code for compiler intrinsics
  2016-08-08 14:56   ` Carsey, Jaben
@ 2016-08-09  8:13     ` Ard Biesheuvel
  0 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2016-08-09  8:13 UTC (permalink / raw)
  To: Carsey, Jaben
  Cc: Michael Zimmermann, edk2-devel@lists.01.org, Leif Lindholm,
	Daryl McDaniel

On 8 August 2016 at 16:56, Carsey, Jaben <jaben.carsey@intel.com> wrote:
> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
>

Pushed as

78d706e23512 StdLib/LibC: avoid LTO code for compiler intrinsics
1fbd0ca16a99 StdLib/LibC ARM AARCH64: do not redefine compiler intrinsics

Thanks all


>> -----Original Message-----
>> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>> Michael Zimmermann
>> Sent: Monday, August 08, 2016 4:24 AM
>> To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> Cc: Carsey, Jaben <jaben.carsey@intel.com>; edk2-devel@lists.01.org; Leif
>> Lindholm <leif.lindholm@linaro.org>; Daryl McDaniel <edk2-
>> lists@mc2research.org>
>> Subject: Re: [edk2] [PATCH 1/2] StdLib/LibC: avoid LTO code for compiler
>> intrinsics
>> Importance: High
>>
>> Reviewed-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
>>
>> On Mon, Aug 8, 2016 at 1:12 PM, Ard Biesheuvel
>> <ard.biesheuvel@linaro.org>
>> wrote:
>>
>> > The softfloat routines and some other routines supplied by LibC
>> > will satisfy references to compiler intrinsics that are emitted
>> > by the compiler backend, which under LTO means that the link-time
>> > code generation may emit references to symbols that have been
>> > optimized away already.
>> >
>> > Work around this by building the ARM and AARCH64 versions of LibC
>> > and the softfloat library without LTO.
>> >
>> > Contributed-under: TianoCore Contribution Agreement 1.0
>> > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> > ---
>> >  StdLib/LibC/LibC.inf                | 1 +
>> >  StdLib/LibC/Softfloat/Softfloat.inf | 2 +-
>> >  2 files changed, 2 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/StdLib/LibC/LibC.inf b/StdLib/LibC/LibC.inf
>> > index f13630648555..6039bb81c7dd 100644
>> > --- a/StdLib/LibC/LibC.inf
>> > +++ b/StdLib/LibC/LibC.inf
>> > @@ -120,3 +120,4 @@ [LibraryClasses]
>> >  #
>> >  [BuildOptions]
>> >    MSFT:*_*_IA32_CC_FLAGS = /GL-
>> > +  GCC:*_*_ARM_CC_FLAGS = -fno-lto
>> > diff --git a/StdLib/LibC/Softfloat/Softfloat.inf b/StdLib/LibC/Softfloat/
>> > Softfloat.inf
>> > index 99763bcb57ba..460406c38fa4 100644
>> > --- a/StdLib/LibC/Softfloat/Softfloat.inf
>> > +++ b/StdLib/LibC/Softfloat/Softfloat.inf
>> > @@ -71,4 +71,4 @@ [Packages]
>> >  # Nasty things could happen if you do.
>> >
>> >  [BuildOptions]
>> > -  GCC:*_*_*_CC_FLAGS  = -DSOFTFLOAT_FOR_GCC -Wno-enum-compare
>> > -fno-tree-vrp
>> > +  GCC:*_*_*_CC_FLAGS  = -DSOFTFLOAT_FOR_GCC -Wno-enum-
>> compare
>> > -fno-tree-vrp -fno-lto
>> > --
>> > 2.7.4
>> >
>> >
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel


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

end of thread, other threads:[~2016-08-09  8:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-08 11:12 [PATCH 1/2] StdLib/LibC: avoid LTO code for compiler intrinsics Ard Biesheuvel
2016-08-08 11:12 ` [PATCH 2/2] StdLib/LibC ARM AARCH64: do not redefine " Ard Biesheuvel
2016-08-08 14:56   ` Carsey, Jaben
2016-08-08 11:24 ` [PATCH 1/2] StdLib/LibC: avoid LTO code for " Michael Zimmermann
2016-08-08 14:56   ` Carsey, Jaben
2016-08-09  8:13     ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox