[ELDK] [PATCH] usr/include/error.h, argp.h, and n?curses.h

Detlev Zundel dzu at denx.de
Fri Sep 25 16:05:11 CEST 2009


Hy Ryan,

> #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.

I'm sorry, but this really makes no sense for me.

> 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.

It's nice that you gave code, so I can try to reproduce it.

> 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)

Did you use native or cross-toolchain?

This is my result with native toolchain:

  bash-3.2# cat header.h
  #include <stdint.h>
  struct foo {
  	uint8_t v1;
  	uint8_t v2;
  	uint8_t v3;
  	uint16_t v4;
  } __attribute__((packed));
  bash-3.2# cat s1.c
  #include <error.h>  /* Breaks __attribute__ */
  #include <stdio.h>
  #include "header.h"
  int main(int argc, char **argv) {
  	printf("%s: sizeof(struct foo) = %d\n", argv[0], sizeof(struct foo));
  	return 0;
  }
  bash-3.2# diff -u s1.c s2.c
  --- s1.c	2009-09-25 15:53:28.359560000 +0200
  +++ s2.c	2009-09-25 15:59:17.949560000 +0200
  @@ -1,4 +1,3 @@
  -#include <error.h>  /* Breaks __attribute__ */
   #include <stdio.h>
   #include "header.h"
   int main(int argc, char **argv) {
  bash-3.2# ./s1 ; ./s2
  ./s1: sizeof(struct foo) = 5
  ./s2: sizeof(struct foo) = 5
  bash-3.2# exit

Using the cross-toolchain yields (expectedly) the same result.

> 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.

You fix a problem that we do not have, so I presume the real cause for
your trouble is somewhere else.  Try to find that instead.

Best wishes
  Detlev

-- 
Music scenes ain't real life / They won't get rid of the bomb
Won't eliminate rape / Or bring down the banks / any kind of change
Takes more time and work / than changing channels on a TV set
                                        -- Jello Biafra
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de


More information about the eldk mailing list