[ELDK] [PATCH] usr/include/error.h, argp.h, and n?curses.h
Ryan Thompson
i at ry.ca
Thu Sep 24 19:23:10 CEST 2009
Hello,
#including <error.h>, argp.h or n?curses.h breaks __attribute__ , such
that no __attribute__ types will be applied, on any source (including
other #includes) after the offending #include.
In my case, this resulted in a packed structs not being packed, in a
source file that included error.h. Not surprisingly, the data was
corrupted when passing the "same" struct across different source
files.
Code to reproduce:
header.h:
#include <stdint.h>
struct foo {
uint8_t v1;
uint8_t v2;
uint8_t v3;
uint16_t v4;
} __attribute__((packed));
s1.c:
#include <error.h> /* Breaks __attribute__ */
#include <stdio.h>
#include "header.h"
int main(void) {
printf("s1: sizeof(struct foo) = %d\n", sizeof(struct foo));
return 0;
}
s2.c:
#include <stdio.h>
#include "header.h"
int main(void) {
printf("s2: sizeof(struct foo) = %d\n", sizeof(struct foo));
return 0;
}
Output of both programs:
s1: sizeof(struct foo) = 6 # Wrong!
s2: sizeof(struct foo) = 5 # Right
Version tested:
ELDK 2008-04-01 (From
http://ftp.denx.de/pub/eldk/4.2/ppc-linux-x86/iso/ppc-2008-04-01.iso)
The Fix:
My patch removes __attribute__ redefinition from the eldk's include
files. This code appears to be a defensive kludge for GCC < 2.5, so
the risk of regressions on GCC 4.x is extremely low.
-------------------------8<----------------------------------------------------------
diff -urN eldk.orig/ppc_4xx/usr/include/argp.h eldk/ppc_4xx/usr/include/argp.h
--- eldk.orig/ppc_4xx/usr/include/argp.h 2008-04-01 08:39:05.000000000 -0600
+++ eldk/ppc_4xx/usr/include/argp.h 2009-09-23 16:42:54.000000000 -0600
@@ -41,19 +41,6 @@
# define __NTH(fct) fct __THROW
#endif
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
-# define __attribute__(Spec) /* empty */
-# endif
-/* The __-protected variants of `format' and `printf' attributes
- are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || __STRICT_ANSI__
-# define __format__ format
-# define __printf__ printf
-# endif
-#endif
-
/* GCC 2.95 and later have "__restrict"; C99 compilers have
"restrict", and "configure" may have defined "restrict". */
#ifndef __restrict
diff -urN eldk.orig/ppc_4xx/usr/include/curses.h
eldk/ppc_4xx/usr/include/curses.h
--- eldk.orig/ppc_4xx/usr/include/curses.h 2008-04-01 09:17:12.000000000 -0600
+++ eldk/ppc_4xx/usr/include/curses.h 2009-09-23 16:40:04.000000000 -0600
@@ -503,17 +503,6 @@
#endif /* NCURSES_EXT_FUNCS */
/*
- * GCC (and some other compilers) define '__attribute__'; we're using this
- * macro to alert the compiler to flag inconsistencies in printf/scanf-like
- * function calls. Just in case '__attribute__' isn't defined, make a dummy.
- * Old versions of G++ do not accept it anyway, at least not consistently with
- * GCC.
- */
-#if !(defined(__GNUC__) || defined(__GNUG__) || defined(__attribute__))
-#define __attribute__(p) /* nothing */
-#endif
-
-/*
* We cannot define these in ncurses_cfg.h, since they require parameters to be
* passed (that is non-portable). If you happen to be using gcc with warnings
* enabled, define
diff -urN eldk.orig/ppc_4xx/usr/include/error.h eldk/ppc_4xx/usr/include/error.h
--- eldk.orig/ppc_4xx/usr/include/error.h 2009-09-23 16:11:17.000000000 -0600
+++ eldk/ppc_4xx/usr/include/error.h 2009-09-23 15:57:12.000000000 -0600
@@ -20,19 +20,6 @@
#ifndef _ERROR_H
#define _ERROR_H 1
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
-# define __attribute__(Spec) /* empty */
-# endif
-/* The __-protected variants of `format' and `printf' attributes
- are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __format__ format
-# define __printf__ printf
-# endif
-#endif
-
#ifdef __cplusplus
extern "C" {
#endif
diff -urN eldk.orig/ppc_4xx/usr/include/ncurses/curses.h
eldk/ppc_4xx/usr/include/ncurses/curses.h
--- eldk.orig/ppc_4xx/usr/include/ncurses/curses.h 2008-04-01
09:17:12.000000000 -0600
+++ eldk/ppc_4xx/usr/include/ncurses/curses.h 2009-09-23
16:40:04.000000000 -0600
@@ -503,17 +503,6 @@
#endif /* NCURSES_EXT_FUNCS */
/*
- * GCC (and some other compilers) define '__attribute__'; we're using this
- * macro to alert the compiler to flag inconsistencies in printf/scanf-like
- * function calls. Just in case '__attribute__' isn't defined, make a dummy.
- * Old versions of G++ do not accept it anyway, at least not consistently with
- * GCC.
- */
-#if !(defined(__GNUC__) || defined(__GNUG__) || defined(__attribute__))
-#define __attribute__(p) /* nothing */
-#endif
-
-/*
* We cannot define these in ncurses_cfg.h, since they require parameters to be
* passed (that is non-portable). If you happen to be using gcc with warnings
* enabled, define
diff -urN eldk.orig/ppc_4xx/usr/include/ncurses/ncurses.h
eldk/ppc_4xx/usr/include/ncurses/ncurses.h
--- eldk.orig/ppc_4xx/usr/include/ncurses/ncurses.h 2008-04-01
09:17:12.000000000 -0600
+++ eldk/ppc_4xx/usr/include/ncurses/ncurses.h 2009-09-23
16:40:04.000000000 -0600
@@ -503,17 +503,6 @@
#endif /* NCURSES_EXT_FUNCS */
/*
- * GCC (and some other compilers) define '__attribute__'; we're using this
- * macro to alert the compiler to flag inconsistencies in printf/scanf-like
- * function calls. Just in case '__attribute__' isn't defined, make a dummy.
- * Old versions of G++ do not accept it anyway, at least not consistently with
- * GCC.
- */
-#if !(defined(__GNUC__) || defined(__GNUG__) || defined(__attribute__))
-#define __attribute__(p) /* nothing */
-#endif
-
-/*
* We cannot define these in ncurses_cfg.h, since they require parameters to be
* passed (that is non-portable). If you happen to be using gcc with warnings
* enabled, define
diff -urN eldk.orig/ppc_4xx/usr/include/ncurses.h
eldk/ppc_4xx/usr/include/ncurses.h
--- eldk.orig/ppc_4xx/usr/include/ncurses.h 2008-04-01 09:17:12.000000000 -0600
+++ eldk/ppc_4xx/usr/include/ncurses.h 2009-09-23 16:40:04.000000000 -0600
@@ -503,17 +503,6 @@
#endif /* NCURSES_EXT_FUNCS */
/*
- * GCC (and some other compilers) define '__attribute__'; we're using this
- * macro to alert the compiler to flag inconsistencies in printf/scanf-like
- * function calls. Just in case '__attribute__' isn't defined, make a dummy.
- * Old versions of G++ do not accept it anyway, at least not consistently with
- * GCC.
- */
-#if !(defined(__GNUC__) || defined(__GNUG__) || defined(__attribute__))
-#define __attribute__(p) /* nothing */
-#endif
-
-/*
* We cannot define these in ncurses_cfg.h, since they require parameters to be
* passed (that is non-portable). If you happen to be using gcc with warnings
* enabled, define
diff -urN eldk.orig/ppc_4xxFP/usr/include/error.h
eldk/ppc_4xxFP/usr/include/error.h
--- eldk.orig/ppc_4xxFP/usr/include/error.h 2008-04-01 12:16:41.000000000 -0600
+++ eldk/ppc_4xxFP/usr/include/error.h 2009-09-23 16:11:43.000000000 -0600
@@ -20,19 +20,6 @@
#ifndef _ERROR_H
#define _ERROR_H 1
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
-# define __attribute__(Spec) /* empty */
-# endif
-/* The __-protected variants of `format' and `printf' attributes
- are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __format__ format
-# define __printf__ printf
-# endif
-#endif
-
#ifdef __cplusplus
extern "C" {
#endif
More information about the eldk
mailing list