[2/7] Don't disable SSE in x86-64 ld.so
Commit Message
On Tue, Aug 25, 2015 at 2:31 PM, Roland McGrath <roland@hack.frob.com> wrote:
> I meant a comment for the CFLAGS-.os setting, but close enough.
>
> However, the x86_64/Makefile bit needs a comment for its CFLAGS-.os
> setting that explains why -mno-mmx is necessary in ld.so code.
We use -mno-mmx on i386 since mm registers are passed to pass
__m64 arguments. On x86-64, I can't think of a good reason to use
MMX in ld.so.
Here is the updated patch.
Comments
> We use -mno-mmx on i386 since mm registers are passed to pass
> __m64 arguments. On x86-64, I can't think of a good reason to use
> MMX in ld.so.
The patch is OK now since -mno-mmx was the status quo ante for x86_64.
But the rationale for -mno-mmx is being stated in a backwards fashion.
We should add special options only if there is a good reason to have
them. If you just don't think it's optimal to use MMX, then that is not
a good reason to use -mno-mmx; it's a good reason to make some compiler
change to improve optimization. If there is a specific, known,
pathological optimization issue, then there should be a GCC bug filed
for that and the comments in the makefile should point to that bug. If
there is no such reason to specifically use -mno-mmx, then we should
drop it.
On Tue, Aug 25, 2015 at 2:48 PM, Roland McGrath <roland@hack.frob.com> wrote:
>> We use -mno-mmx on i386 since mm registers are passed to pass
>> __m64 arguments. On x86-64, I can't think of a good reason to use
>> MMX in ld.so.
>
> The patch is OK now since -mno-mmx was the status quo ante for x86_64.
>
> But the rationale for -mno-mmx is being stated in a backwards fashion.
> We should add special options only if there is a good reason to have
> them. If you just don't think it's optimal to use MMX, then that is not
> a good reason to use -mno-mmx; it's a good reason to make some compiler
> change to improve optimization. If there is a specific, known,
> pathological optimization issue, then there should be a GCC bug filed
> for that and the comments in the makefile should point to that bug. If
> there is no such reason to specifically use -mno-mmx, then we should
> drop it.
Here is a partial list of MMX bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48397
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47759
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40983
From f65ffc892e43fb90ed3235a30e3cecb0faa3f0d6 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 28 Jul 2015 18:56:18 -0700
Subject: [PATCH] Don't disable SSE in x86-64 ld.so
Since x86-64 ld.so preserves vector registers now, we can use SSE in
x86-64 ld.so. We should run tst-ld-sse-use.sh only on i386.
* sysdeps/x86/Makefile [$(subdir) == elf] (CFLAGS-.os,
tests-special, $(objpfx)tst-ld-sse-use.out): Moved to ...
* sysdeps/i386/Makefile [$(subdir) == elf] (CFLAGS-.os,
tests-special, $(objpfx)tst-ld-sse-use.out): Here. Update
comments.
* sysdeps/x86_64/Makefile [$(subdir) == elf] (CFLAGS-.os): Add
-mno-mmx for $(all-rtld-routines).
* sysdeps/x86/tst-ld-sse-use.sh: Moved to ...
* sysdeps/i386/tst-ld-sse-use.sh: Here. Replace x86-64 with
i386.
---
sysdeps/i386/Makefile | 14 ++++++++++++++
sysdeps/{x86 => i386}/tst-ld-sse-use.sh | 2 +-
sysdeps/x86/Makefile | 11 -----------
sysdeps/x86_64/Makefile | 4 ++++
4 files changed, 19 insertions(+), 12 deletions(-)
rename sysdeps/{x86 => i386}/tst-ld-sse-use.sh (97%)
@@ -83,3 +83,17 @@ endif
ifeq ($(subdir),csu)
gen-as-const-headers += tlsdesc.sym
endif
+
+ifeq ($(subdir),elf)
+# Make sure no code in ld.so uses mm/xmm/ymm/zmm registers on i386 since
+# the first 3 mm/xmm/ymm/zmm registers are used to pass vector parameters
+# which must be preserved.
+CFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),\
+ -mno-sse -mno-mmx)
+
+tests-special += $(objpfx)tst-ld-sse-use.out
+$(objpfx)tst-ld-sse-use.out: ../sysdeps/i386/tst-ld-sse-use.sh $(objpfx)ld.so
+ @echo "Checking ld.so for SSE register use. This will take a few seconds..."
+ $(BASH) $< $(objpfx) '$(NM)' '$(OBJDUMP)' '$(READELF)' > $@; \
+ $(evaluate-test)
+endif
similarity index 97%
rename from sysdeps/x86/tst-ld-sse-use.sh
rename to sysdeps/i386/tst-ld-sse-use.sh
@@ -1,5 +1,5 @@
#! /bin/bash
-# Make sure no code in ld.so uses xmm/ymm/zmm registers on x86-64.
+# Make sure no code in ld.so uses xmm/ymm/zmm registers on i386.
# Copyright (C) 2009-2015 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
@@ -1,14 +1,3 @@
-ifeq ($(subdir),elf)
-CFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),\
- -mno-sse -mno-mmx)
-
-tests-special += $(objpfx)tst-ld-sse-use.out
-$(objpfx)tst-ld-sse-use.out: ../sysdeps/x86/tst-ld-sse-use.sh $(objpfx)ld.so
- @echo "Checking ld.so for SSE register use. This will take a few seconds..."
- $(BASH) $< $(objpfx) '$(NM)' '$(OBJDUMP)' '$(READELF)' > $@; \
- $(evaluate-test)
-endif
-
ifeq ($(subdir),csu)
gen-as-const-headers += cpu-features-offsets.sym rtld-global-offsets.sym
endif
@@ -19,6 +19,10 @@ gen-as-const-headers += locale-defines.sym
endif
ifeq ($(subdir),elf)
+# There is no good reason to use MMX in x86-64 ld.so with GCC.
+CFLAGS-.os += $(if $(filter $(@F),$(patsubst %,%.os,$(all-rtld-routines))),\
+ -mno-mmx)
+
sysdep-dl-routines += tlsdesc dl-tlsdesc
tests += ifuncmain8
--
2.4.3