diff options
-rw-r--r-- | cparser/Elab.ml | 2 | ||||
-rw-r--r-- | ia32/PrintAsm.ml | 4 | ||||
-rw-r--r-- | test/regression/Makefile | 2 | ||||
-rw-r--r-- | test/regression/Results/attribs1 | 4 | ||||
-rw-r--r-- | test/regression/attribs1.c | 39 |
5 files changed, 47 insertions, 4 deletions
diff --git a/cparser/Elab.ml b/cparser/Elab.ml index 6c148362..f6731e47 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -280,7 +280,7 @@ let elab_attribute loc = function | ("const", []) -> [AConst] | ("restrict", []) -> [ARestrict] | ("volatile", []) -> [AVolatile] - | (("attribute" | "__attribute__"), l) -> + | (("__attribute" | "__attribute__"), l) -> List.flatten (List.map (elab_gcc_attr loc) l) | (name, _) -> warning loc "`%s' annotation ignored" name; [] diff --git a/ia32/PrintAsm.ml b/ia32/PrintAsm.ml index 33aae6a3..969b3b30 100644 --- a/ia32/PrintAsm.ml +++ b/ia32/PrintAsm.ml @@ -136,8 +136,8 @@ let section oc name = let name_of_section_ELF = function | Section_text -> ".text" | Section_data i | Section_small_data i -> if i then ".data" else ".bss" - | Section_const | Section_small_const -> ".rodata" - | Section_string -> ".rodata" + | Section_const | Section_small_const -> ".section .rodata" + | Section_string -> ".section .rodata" | Section_literal -> ".section .rodata.cst8,\"aM\",@progbits,8" | Section_jumptable -> ".text" | Section_user(s, wr, ex) -> diff --git a/test/regression/Makefile b/test/regression/Makefile index 377d2050..5de19cc2 100644 --- a/test/regression/Makefile +++ b/test/regression/Makefile @@ -8,7 +8,7 @@ LIBS=$(LIBMATH) # Can run and have reference output in Results -TESTS=bitfields1 bitfields2 bitfields3 bitfields4 \ +TESTS=attribs1 bitfields1 bitfields2 bitfields3 bitfields4 \ bitfields5 bitfields6 bitfields7 \ expr1 initializers volatile2 \ funct3 expr5 struct7 struct8 casts1 casts2 char1 \ diff --git a/test/regression/Results/attribs1 b/test/regression/Results/attribs1 new file mode 100644 index 00000000..e9954741 --- /dev/null +++ b/test/regression/Results/attribs1 @@ -0,0 +1,4 @@ +Address of a = 0 mod 16 +Address of b = 0 mod 8 +Delta d - c = 4 +Delta f - e = 4 diff --git a/test/regression/attribs1.c b/test/regression/attribs1.c new file mode 100644 index 00000000..21d7556c --- /dev/null +++ b/test/regression/attribs1.c @@ -0,0 +1,39 @@ +/* gcc-style "aligned" and "section" attributes */ + +/* Caveat: some C standard libraries, when preprocessed with -U__GNUC__, + #define away __attribute__, so we use __attribute in the following. */ + +#include <stdio.h> + +/* Alignment */ + +char filler1 = 1; +__attribute((__aligned__(16))) int a = 1234; +char filler2 = 1; +__attribute((__aligned__(8))) char b = 'b'; + +/* Sections */ + +__attribute((__section__("mydata"))) int c = 78; +char filler3 = 1; +__attribute((__section__("mydata"))) int d = 90; + +__attribute((__section__("myconst"))) const int e = 12; +const char filler4 = 1; +__attribute((__section__("myconst"))) const int f = 34; + +__attribute((__section__("mycode"))) int myfunc(int x) { return x + 1; } + +/* Test harness */ + +int main() +{ + printf("Address of a = %u mod 16\n", ((unsigned int) &a) & 0xF); + printf("Address of b = %u mod 8\n", ((unsigned int) &b) & 0x7); + printf("Delta d - c = %u\n", ((unsigned int) &d) - ((unsigned int) &c)); + printf("Delta f - e = %u\n", ((unsigned int) &f) - ((unsigned int) &e)); + return 0; +} + + + |