[v2] fixincludes: vxworks: regs.h: Fix includes in regs.h wrapper

Message ID 20181008130304.19827-1-rv@rasmusvillemoes.dk
State New
Headers show
Series
  • [v2] fixincludes: vxworks: regs.h: Fix includes in regs.h wrapper
Related show

Commit Message

Rasmus Villemoes Oct. 8, 2018, 1:03 p.m.
A quick experiment reveals that this hack is needed for C code - simply
removing this hack entirely breaks the build of libstdc++, since
regs.h (more accurately, the cpu-specific header it pulls in) defines
structs in terms of types from vxTypesOld. Those definitions are
properly guarded by #ifndef _ASMLANGUAGE, but the cpu-files do not take
care to include vxTypesOld.h for the types they depend on.

But when using regs.h from some assembly file, the assembler chokes on
the typedefs in vxTypesOld.h. We can fix that by guarding the include of
vxTypesOld by !_ASMLANGUAGE. This should not affect existing C code.

Now, the OS' regs.h contains preprocessor conditionals such as

#if     CPU_FAMILY==I960
...
#endif  /* CPU_FAMILY==I960 */
#if     CPU_FAMILY==MC680X0
...
#endif  /* CPU_FAMILY==MC680X0 */

Without definitions of CPU_FAMILY, I960 etc., these would all be true,
which will not end well. Code using the fix-included regs.h
automatically get vxCpu.h via a chain of includes from vxTypesOld.h, but
we can make regs.h a little more self-contained for both C and asm users
by doing an explicit include of vxCpu.h.

==changelog==

fixincludes/

	* inclhack.def (AAB_vxworks_regs_vxtypes): Add unconditional
	include of vxCpu.h, guard include of vxTypesOld.h by
	!_ASMLANGUAGE.
	* fixincl.x: Regenerate.
---
 fixincludes/inclhack.def | 10 ++++++++++
 1 file changed, 10 insertions(+)

-- 
2.19.1.3.g1d92a00e68

Comments

Olivier Hainque Oct. 15, 2018, 3:14 p.m. | #1
Hi Rasmus,

> On 8 Oct 2018, at 15:03, Rasmus Villemoes <rv@rasmusvillemoes.dk> wrote:

> 

> fixincludes/

> 

> 	* inclhack.def (AAB_vxworks_regs_vxtypes): Add unconditional

> 	include of vxCpu.h, guard include of vxTypesOld.h by

> 	!_ASMLANGUAGE.

> 	* fixincl.x: Regenerate.


Good for me, thanks.

Patch

diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def
index f9ba9774f32..8fd9f7ef295 100644
--- a/fixincludes/inclhack.def
+++ b/fixincludes/inclhack.def
@@ -426,7 +426,17 @@  fix = {
     replace     = <<- _EndOfHeader_
 	#ifndef _REGS_H
 	#define _REGS_H
+	/* regs.h depends on CPU_FAMILY being properly defined, which
+	   is done by vxCpu.h.  */
+	#include <types/vxCpu.h>
+	/* regs.h includes a CPU_FAMILY-specific header that requires
+	   vxTypesOld.h to already have been included.  Those headers
+	   contain proper _ASMLANGUAGE guards around their typedefs,
+	   but vxTypesOld.h itself does not. So we avoid including
+	   vxTypesOld.h from assembly.  */
+	#ifndef _ASMLANGUAGE
 	#include <types/vxTypesOld.h>
+	#endif
 	#include_next <arch/../regs.h>
 	#endif
 	_EndOfHeader_;