Skip to contentSkip to conversation

xen: Deal with stdarg.h and -nostdinc

PATCH In review Christoph Egger 5 participants 11 messages May 26, 2011 – May 27, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: Deal with stdarg.h and -nostdinc

For compiling the xen kernel we use -nostdinc which means we don't want to rely on any external headers. That also counts vor stdarg.h.

Use the external header when we compile the tools. Adapt libelf-loader.c which is compiled in the kernel and with the tools.

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
xen/common/libelf/libelf-loader.c +1 -1
diff -r 24b01e02ea17 xen/common/libelf/libelf-loader.c
@@ -16,7 +16,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <stdarg.h>
+#include "../../include/xen/stdarg.h"
 
 #include "libelf-private.h"
 
xen/include/xen/stdarg.h +10 -2
diff -r 24b01e02ea17 xen/include/xen/stdarg.h
@@ -1,5 +1,13 @@
-#if defined(__OpenBSD__)
-#  include "/usr/include/stdarg.h"
+#ifndef _XEN_STDARG_H_
+#define _XEN_STDARG_H_
+
+#if defined(__XEN__)
+typedef __builtin_va_list va_list;
+#define va_start(ap, last)    __builtin_stdarg_start((ap), (last))
+#define va_end(ap)            __builtin_va_end(ap)
+#define va_arg                __builtin_va_arg
 #else
 #  include <stdarg.h>
 #endif
+
+#endif	/* _XEN_STDARG_H_ */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 11 lines · Christoph Egger

For compiling the xen kernel we use -nostdinc which means we don't want to rely on any external headers. That also counts vor stdarg.h.

Use the external header when we compile the tools. Adapt libelf-loader.c which is compiled in the kernel and with the tools.

Forgot to mention: Please apply this to xen-4.1-testing, too.

Christoph

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#2 lore raw
In reply to Christoph Egger
Quoted 10 lines · Christoph Egger

For compiling the xen kernel we use -nostdinc which means we don't want to rely on any external headers. That also counts vor stdarg.h.

Use the external header when we compile the tools. Adapt libelf-loader.c which is compiled in the kernel and with the tools.

Does the current approach not work for you?

-- Keir

#3 lore raw
In reply to Christoph Egger
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Christoph Egger

For compiling the xen kernel we use -nostdinc which means we don't want to rely on any external headers. That also counts vor stdarg.h.

I think using compiler provided headers is fine, and I have to admit I don't like the open-coding of various definitions to gcc builtins - if gcc changes anything here, we'll break (which after all is why the compiler provides this header instead of the platform).

Jan

Quoted 5 lines

Use the external header when we compile the tools. Adapt libelf-loader.c which is compiled in the kernel and with the tools.

#4 lore raw
In reply to Christoph Egger

Christoph Egger writes ("[Xen-devel] [PATCH] xen: Deal with stdarg.h and -nostdinc"):

Quoted 3 lines

For compiling the xen kernel we use -nostdinc which means we don't want to rely on any external headers. That also counts vor stdarg.h.

Right, OK, but:

Quoted 3 lines

Use the external header when we compile the tools. Adapt libelf-loader.c which is compiled in the kernel and with the tools.

-#include <stdarg.h>
+#include "../../include/xen/stdarg.h"

Firstly, is this correct for all uses of libelf-loader ? This file is compiled both for use inside Xen and for use on the host. In the latter case it /should/ use the system's stdarg.h.

Also, this kind of relative path should not be necessary. The relevant files should be on the include path.

So I think this should be fixed by arranging that your new stdarg.h is on the relevant include path, not by changing the .c file.

Ian.

#5 lore raw
Quoted 7 lines · Ian Jackson

Christoph Egger writes ("[Xen-devel] [PATCH] xen: Deal with stdarg.h and -nostdinc"):

Quoted 3 lines

For compiling the xen kernel we use -nostdinc which means we don't want to rely on any external headers. That also counts vor stdarg.h.

Right, OK, but:

Not really. We are only doing the same as Linux right now. I do note that they add an -isystem option to their command line, with a gcc include path that they presumably dump out of gcc in some standard way. However, our current approach seems to work, if it fails to work in some situation it is likely to be pretty obvious (build or link failure), and we can fix it then. This stuff can be moderately fragile, and we've now had no actual bug reports about it in a long while.

-- Keir

Quoted 23 lines
Quoted 3 lines

Use the external header when we compile the tools. Adapt libelf-loader.c which is compiled in the kernel and with the tools.

xen/common/libelf/libelf-loader.c +1 -1
-#include <stdarg.h>
+#include "../../include/xen/stdarg.h"

Firstly, is this correct for all uses of libelf-loader ? This file is compiled both for use inside Xen and for use on the host. In the latter case it /should/ use the system's stdarg.h.

Also, this kind of relative path should not be necessary. The relevant files should be on the include path.

So I think this should be fixed by arranging that your new stdarg.h is on the relevant include path, not by changing the .c file.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#6 lore raw
Quoted 8 lines · Keir Fraser
Quoted 6 lines · Ian Jackson

Christoph Egger writes ("[Xen-devel] [PATCH] xen: Deal with stdarg.h and -nostdinc"):

Quoted 3 lines

For compiling the xen kernel we use -nostdinc which means we don't want to rely on any external headers. That also counts vor stdarg.h.

Quoted 7 lines
Quoted 1 line

Right, OK, but:

Not really. We are only doing the same as Linux right now. I do note that they add an -isystem option to their command line, with a gcc include path that they presumably dump out of gcc in some standard way. However, our current approach seems to work, if it fails to work in some situation it is likely to be pretty obvious (build or link failure), and we can fix it then.

The cross-compiling facility in NetBSD has been further improved which made gcc more pendantic for this. -nostdinc is used and -isystem is *not* used.

Quoted 2 lines

This stuff can be moderately fragile, and we've now had no actual bug reports about it in a long while.

Here is a full error message:

gcc -O2 -I/usr/include -I/usr/pkg/include -O2 -fomit-frame-pointer -m64 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -O2 -fomit-frame-pointer -m64 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -O2 -fomit-frame-pointer -m64 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -DNDEBUG -nostdinc -fno-builtin -fno-common -Wredundant-decls -iwithprefix include -Werror -Wno-pointer-arith -pipe -I/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include -I/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/asm-x86/mach-generic -I/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/asm-x86/mach-default -msoft-float -fno-stack-protector -fno-exceptions -mno-red-zone
-fpic -fno-asynchronous-unwind-tables -DGCC_HAS_VISIBILITY_ATTRIBUTE
-g -D__XEN__ -MMD -MF .xen.d -O2 -fomit-frame-pointer -m64 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -DNDEBUG -nostdinc -fno-builtin -fno-common -Wredundant-decls -iwithprefix include -Werror -Wno-pointer-arith -pipe -I/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include -I/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/asm-x86/mach-generic -I/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/asm-x86/mach-default -msoft-float -fno-stack-protector -fno-exceptions -mno-red-zone -fpic -fno-asynchronous-unwind-tables -DGCC_HAS_VISIBILITY_ATTRIBUTE -g -D__XEN__ -MMD -MF .asm-offsets.s.d -S -o asm-offsets.s x86_64/asm-offsets.c In file included from /tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/xen/lib.h:5,
from
/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/asm/system.h:4,
from
/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/xen/spinlock.h:5,
from
/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/xen/sched.h:7,

                 from x86_64/asm-offsets.c:10:

/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/xen/stdarg.h:4:22: error: stdarg.h: No such file or directory In file included from /tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/asm/system.h:4,
from
/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/xen/spinlock.h:5,
from
/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/xen/sched.h:7,

                 from x86_64/asm-offsets.c:10:

/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/xen/lib.h:86: error: expected declaration specifiers or '...' before 'va_list' /tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/xen/lib.h:90: error: expected declaration specifiers or '...' before 'va_list' /tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/xen/lib.h:94: error: expected declaration specifiers or '...' before 'va_list' In file included from /tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/acpi/acpi.h:61,
from
/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/xen/acpi.h:34,
from
/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/acpi/apei.h:8,
from
/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/asm/fixmap.h:23,

                 from x86_64/asm-offsets.c:12:

/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/include/acpi/acpiosxf.h:257: error: expected declaration specifiers or '...' before 'va_list' gmake[3]: *** [asm-offsets.s] Error 1
gmake[3]: Leaving directory `/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/arch/x86'
gmake[2]: *** [/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen/xen] Error 2
gmake[2]: Leaving directory `/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen'
gmake[1]: *** [install] Error 2
gmake[1]: Leaving directory `/tmp/pkgsrc-obj/sysutils/xenkernel41/work.ixp/xen-4.1.0/xen'

Quoted 29 lines

-- Keir

Quoted 23 lines
Quoted 3 lines

Use the external header when we compile the tools. Adapt libelf-loader.c which is compiled in the kernel and with the tools.

(quoted diff) +1 -1
-#include<stdarg.h>
+#include "../../include/xen/stdarg.h"

Firstly, is this correct for all uses of libelf-loader ? This file is compiled both for use inside Xen and for use on the host. In the latter case it /should/ use the system's stdarg.h.

Also, this kind of relative path should not be necessary. The relevant files should be on the include path.

So I think this should be fixed by arranging that your new stdarg.h is on the relevant include path, not by changing the .c file.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#7 lore raw
Quoted 9 lines · Christoph Egger
Quoted 5 lines

Not really. We are only doing the same as Linux right now. I do note that they add an -isystem option to their command line, with a gcc include path that they presumably dump out of gcc in some standard way. However, our current approach seems to work, if it fails to work in some situation it is likely to be pretty obvious (build or link failure), and we can fix it then.

The cross-compiling facility in NetBSD has been further improved which made gcc more pendantic for this. -nostdinc is used and -isystem is *not* used.

So where does NetBSD get its stdarg.h from in this case? It's somewhat bogus to roll your own, as it contains compiler-specific intrinsics.

-- Keir

#8 lore raw
Quoted 8 lines · Keir Fraser
Quoted 6 lines · Christoph Egger
Quoted 5 lines

Not really. We are only doing the same as Linux right now. I do note that they add an -isystem option to their command line, with a gcc include path that they presumably dump out of gcc in some standard way. However, our current approach seems to work, if it fails to work in some situation it is likely to be pretty obvious (build or link failure), and we can fix it then.

Quoted 5 lines
Quoted 3 lines

The cross-compiling facility in NetBSD has been further improved which made gcc more pendantic for this. -nostdinc is used and -isystem is *not* used.

So where does NetBSD get its stdarg.h from in this case?

-isystem must be *explicitely* specified now.

Quoted 3 lines

It's somewhat bogus to roll your own, as it contains compiler-specific intrinsics.

-- Keir

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#9 lore raw
In reply to Christoph Egger

Christoph Egger writes ("Re: [Xen-devel] [PATCH] xen: Deal with stdarg.h and -nostdinc"):

Quoted 3 lines

The cross-compiling facility in NetBSD has been further improved which made gcc more pendantic for this. -nostdinc is used and -isystem is *not* used.

Compiling Xen with some kind of native "cross-compiling facility" provided by NetBSD is NOT SUPPORTED.

Please do NOT send any more patches to Xen to try to make it work.

Ian.

#10 lore raw
In reply to Ian Jackson
Quoted 14 lines · Ian Jackson

Christoph Egger writes ("[Xen-devel] [PATCH] xen: Deal with stdarg.h and -nostdinc"):

Quoted 3 lines

For compiling the xen kernel we use -nostdinc which means we don't want to rely on any external headers. That also counts for stdarg.h.

Right, OK, but:

Quoted 3 lines

Use the external header when we compile the tools. Adapt libelf-loader.c which is compiled in the kernel and with the tools.

(quoted diff) +1 -1
-#include<stdarg.h>
+#include "../../include/xen/stdarg.h"
Quoted 3 lines

Firstly, is this correct for all uses of libelf-loader ? This file is compiled both for use inside Xen and for use on the host. In the latter case it /should/ use the system's stdarg.h.

This is exactly what happens in conjunction with the other diff. In the first case there is __XEN__ defined and in the latter case __XEN__ is *not* defined.

Quoted 2 lines

Also, this kind of relative path should not be necessary. The relevant files should be on the include path.

I tried <xen/stdarg.h> but then compiling the tools failed.

Quoted 5 lines

So I think this should be fixed by arranging that your new stdarg.h is on the relevant include path, not by changing the .c file.

Ian.

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632