Skip to contentSkip to conversation

x86-64: suppress some unneeded side effects of -fPIC

PATCH In review Jan Beulich 2 participants 7 messages Sep 12, 2006 – Sep 13, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86-64: suppress some unneeded side effects of -fPIC

Full PIC mode isn't needed for Xen, namely is there no need to access data objects via the GOT or call functions through the PLT. Adding -fvisibility=hidden (if the compiler supports it) helps, although it doesn't do as good a job as would be desired (I'm in talks with our compiler guys to understand why).

xen/arch/x86/Rules.mk +20 -17
Index: 2006-09-11/xen/arch/x86/Rules.mk
===================================================================
@@ -11,6 +11,23 @@ HAS_VGA  := y
 pae ?= n
 supervisor_mode_kernel ?= n
 
+# Test for at least GCC v3.2.x.
+gcc-ver = $(shell $(CC) -dumpversion | sed -e 's/^\(.\)\.\(.\)\.\(.\)/\$(1)/')
+ifeq ($(call gcc-ver,1),1)
+$(error gcc-1.x.x unsupported - upgrade to at least gcc-3.2.x)
+endif
+ifeq ($(call gcc-ver,1),2)
+$(error gcc-2.x.x unsupported - upgrade to at least gcc-3.2.x)
+endif
+ifeq ($(call gcc-ver,1),3)
+ifeq ($(call gcc-ver,2),0)
+$(error gcc-3.0.x unsupported - upgrade to at least gcc-3.2.x)
+endif
+ifeq ($(call gcc-ver,2),1)
+$(error gcc-3.1.x unsupported - upgrade to at least gcc-3.2.x)
+endif
+endif
+
 CFLAGS  += -nostdinc -fno-builtin -fno-common -fno-strict-aliasing
 CFLAGS  += -iwithprefix include -Werror -Wno-pointer-arith -pipe
 CFLAGS  += -I$(BASEDIR)/include 
@@ -41,6 +58,9 @@ endif
 
 ifeq ($(TARGET_SUBARCH),x86_64)
 CFLAGS  += -mno-red-zone -fpic -fno-reorder-blocks
+ifneq ($(call gcc-ver,1),3)
+CFLAGS  += -fvisibility=hidden
+endif
 CFLAGS  += -fno-asynchronous-unwind-tables
 LDFLAGS += -m elf_x86_64
 x86_32 := n
@@ -50,20 +70,3 @@ endif
 HDRS += $(wildcard $(BASEDIR)/include/asm-x86/hvm/*.h)
 HDRS += $(wildcard $(BASEDIR)/include/asm-x86/hvm/svm/*.h)
 HDRS += $(wildcard $(BASEDIR)/include/asm-x86/hvm/vmx/*.h)
-
-# Test for at least GCC v3.2.x.
-gcc-ver = $(shell $(CC) -dumpversion | sed -e 's/^\(.\)\.\(.\)\.\(.\)/\$(1)/')
-ifeq ($(call gcc-ver,1),1)
-$(error gcc-1.x.x unsupported - upgrade to at least gcc-3.2.x)
-endif
-ifeq ($(call gcc-ver,1),2)
-$(error gcc-2.x.x unsupported - upgrade to at least gcc-3.2.x)
-endif
-ifeq ($(call gcc-ver,1),3)
-ifeq ($(call gcc-ver,2),0)
-$(error gcc-3.0.x unsupported - upgrade to at least gcc-3.2.x)
-endif
-ifeq ($(call gcc-ver,2),1)
-$(error gcc-3.1.x unsupported - upgrade to at least gcc-3.2.x)
-endif
-endif
#1 lore raw
Quoted 8 lines · Jan Beulich

Full PIC mode isn't needed for Xen, namely is there no need to access data objects via the GOT or call functions through the PLT. Adding -fvisibility=hidden (if the compiler supports it) helps, although it doesn't do
as good a job as would be desired (I'm in talks with our compiler guys to understand why).

What overheads does this remove? Does it actually shorten code sequences?

It seems that some gcc v3 compilers have -fvisibility=hidden too (e.g. My gcc-3.4.4 does). I thus checked in a patch that checks for availability of this feature in a 'test-gcc-flag' style of way (as defined in Config.mk), rather than doing a gcc version test.

-- Keir

#2 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 13.09.06 14:46 >>>

Quoted 7 lines · Jan Beulich

Full PIC mode isn't needed for Xen, namely is there no need to access data objects via the GOT or call functions through the PLT. Adding -fvisibility=hidden (if the compiler supports it) helps, although it doesn't do
as good a job as would be desired (I'm in talks with our compiler guys to understand why).

Quoted 3 lines
Quoted 1 line

What overheads does this remove? Does it actually shorten code sequences?

It allows global data objects to be accessed without going through the GOT.

Quoted 4 lines

It seems that some gcc v3 compilers have -fvisibility=hidden too (e.g. My gcc-3.4.4 does). I thus checked in a patch that checks for availability of this feature in a 'test-gcc-flag' style of way (as defined in Config.mk), rather than doing a gcc version test.

Hmm, bad luck, this time I had hoped it'll take you a little longer to commit it, as we've found a better solution: Using #pragma GCC visibility, *all* data references benefit, not just the ones to objects defined in the same translation unit. However, as this now is a header file change, detection logic cannot be used as nicely, so I guess we want to keep the previous change and add this one on top.

xen/include/xen/compiler.h +4 -0
Index: 2006-09-11/xen/include/xen/compiler.h
===================================================================
@@ -35,6 +35,10 @@
 #define offsetof(a,b) ((unsigned long)&(((a *)0)->b))
 #endif
 
+#if defined(__x86_64__) && (__GNUC__ > 3)
+#pragma GCC visibility push(hidden)
+#endif
+
 /* This macro obfuscates arithmetic on a variable address so that gcc
    shouldn't recognize the original var, and make assumptions about it */
 /*
#3 lore raw
Quoted 8 lines · Jan Beulich

Hmm, bad luck, this time I had hoped it'll take you a little longer to commit it, as we've found a better solution: Using #pragma GCC visibility, *all* data references benefit, not just the ones to objects defined in the same translation unit. However, as this now is a header file change, detection logic cannot be used as nicely, so I guess we want to keep the previous change and add this one on top.

It does stack okay on top of command-line option? I'm assuming so, and I'll check in this new patch in addition to the one I already committed.

-- Keir

#4 lore raw
Quoted 11 lines · Keir Fraser
Quoted 8 lines

Hmm, bad luck, this time I had hoped it'll take you a little longer to commit it, as we've found a better solution: Using #pragma GCC visibility, *all* data references benefit, not just the ones to objects defined in the same translation unit. However, as this now is a header file change, detection logic cannot be used as nicely, so I guess we want to keep the previous change and add this one on top.

It does stack okay on top of command-line option? I'm assuming so, and I'll check in this new patch in addition to the one I already committed.

Actually, another question first: if gcc does not understand the pragma will it silently ignore it? Then we could get rid of check for GNUC>3, and we could get rid of -fvisibility=hidden too.

-- Keir

#5 lore raw
Quoted 6 lines · Keir Fraser
Quoted 2 lines

It does stack okay on top of command-line option? I'm assuming so, and I'll check in this new patch in addition to the one I already committed.

Actually, another question first: if gcc does not understand the pragma will it silently ignore it? Then we could get rid of check for GNUC>3, and we could get rid of -fvisibility=hidden too.

Answered my own question. We need the check. So I'll apply the patch as is.

-- Keir

#6 lore raw
In reply to Keir Fraser
Quoted 9 lines
Quoted 1 line
Quoted 1 line

Keir Fraser <[email protected]> 13.09.06 15:15 >>>

Quoted 7 lines · Keir Fraser
Quoted 7 lines

Hmm, bad luck, this time I had hoped it'll take you a little longer to commit it, as we've found a better solution: Using #pragma GCC visibility, *all* data references benefit, not just the ones to objects defined in the same translation unit. However, as this now is a header file change, detection logic cannot be used as nicely, so I guess we want to keep the previous change and add this one on top.

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

It does stack okay on top of command-line option? I'm assuming so, and I'll check in this new patch in addition to the one I already committed.

Yes, it should.

Quoted 3 lines

Actually, another question first: if gcc does not understand the pragma will it silently ignore it? Then we could get rid of check for GNUC>3, and we could get rid of -fvisibility=hidden too.

You'd get a warning, which is being turned into an error by the build scripts.

Jan