Skip to content

Commit 709cb9e

Browse files
committed
compilation of misc tests
0 parents  commit 709cb9e

35 files changed

+536
-0
lines changed

Makefile

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# CTF Tests
3+
#
4+
5+
CTFDIFF = ctfdiff
6+
FILES = \
7+
array.o \
8+
bare1.o \
9+
bitfields.o \
10+
dedup.o \
11+
empty.o \
12+
enum.o \
13+
extern.o \
14+
file.o \
15+
int.o \
16+
float.o \
17+
func.o \
18+
fptr.o \
19+
packstruct.o \
20+
starr.o \
21+
static.o \
22+
stack.o \
23+
siginfo.o \
24+
struct.o \
25+
typedef.o \
26+
union.o \
27+
union-bits.o \
28+
vla.o \
29+
weak.o
30+
31+
CFLAGS = -g -Werror
32+
CTFFILES = $(FILES:%.o=%.ctf) $(FILES:%.o=%.ctf.orig)
33+
DIFFFILES = $(FILES:%.o=%.diff)
34+
DIFFFLAGS = -t -o -f
35+
CC = gcc
36+
37+
stack.o := CFLAGS += -m64
38+
39+
%.o: %.c
40+
$(CC) $(CFLAGS) -c $< -o $@
41+
42+
%.ctf: %.o
43+
$(CTFCONVERT)-altexec -L VERSION -o $@ $<
44+
45+
%.ctf.orig: %.o
46+
$(CTFCONVERT) -L VERSION -o $@ $<
47+
48+
%.diff: %.ctf %.ctf.orig
49+
$(CTFDIFF) $(DIFFFLAGS) $$(basename $@ .diff).ctf $$(basename $@ .diff).ctf.orig
50+
51+
52+
all: $(CTFFILES)
53+
54+
diff: $(DIFFFILES)
55+
56+
clobber:
57+
rm -f $(FILES) $(CTFFILES)

array.c

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int a[3];
2+
double b[42];
3+
const char *c[] = { "17" "31", "169" };
4+
5+
int d[4][5];
6+
int e[4][5][6];
7+
int f[4][5][6][7];
8+
int g[4][5][6][7][8];
9+
int h[4][5][6][7][8][9];
10+
int i[4][5][6][7][8][9][10];

bare1.c

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* See if we emit the same things when using bare types.
3+
*/
4+
5+
struct a {
6+
int a;
7+
};
8+
9+
typedef struct b {
10+
int b;
11+
} b_t;
12+
13+
enum c {
14+
C = 0
15+
};
16+
17+
typedef enum d {
18+
D = 0
19+
} d_t;
20+
21+
union e {
22+
int e;
23+
};
24+
25+
typedef union f {
26+
int f;
27+
} f_t;

bit-size.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Test that we can generate the right final structure size for the following
3+
* structure.
4+
*/
5+
6+
typedef unsigned long long uint64_t;
7+
typedef struct system_desc {
8+
uint64_t ssd_lolimit:16; /* segment limit 15:0 */
9+
uint64_t ssd_lobase:16; /* segment base 15:0 */
10+
uint64_t ssd_midbase:8; /* segment base 23:16 */
11+
uint64_t ssd_type:4; /* segment type */
12+
uint64_t ssd_zero1:1; /* must be zero */
13+
uint64_t ssd_dpl:2; /* segment descriptor priority level */
14+
uint64_t ssd_p:1; /* segment descriptor present */
15+
uint64_t ssd_hilimit:4; /* segment limit 19:16 */
16+
uint64_t ssd_avl:1; /* available to sw, but not used */
17+
uint64_t ssd_resv1:2; /* unused, ignored */
18+
uint64_t ssd_gran:1; /* limit unit (bytes vs pages) */
19+
uint64_t ssd_hibase:8; /* segment base 31:24 */
20+
uint64_t ssd_hi64base:32; /* segment base 63:32 */
21+
uint64_t ssd_resv2:8; /* unused, ignored */
22+
uint64_t ssd_zero2:5; /* must be zero */
23+
uint64_t ssd_resv3:19; /* unused, ignored */
24+
} system_desc_t;
25+
26+
system_desc_t d;

bitfields.c

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
struct foo {
2+
char start;
3+
int a:3;
4+
int b:5;
5+
char c;
6+
};
7+
8+
#pragma pack(1)
9+
struct bar {
10+
int a:3;
11+
int b:5;
12+
char c;
13+
};
14+
#pragma pack()
15+
16+
struct odd_bits {
17+
char a:2;
18+
char b:4;
19+
char c:2;
20+
long long d:1;
21+
long long e:31;
22+
int f;
23+
};
24+
25+
struct foo a;
26+
struct bar b;
27+
struct odd_bits c;

dedup.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
int a = 3;
2+
3+
int
4+
foo(int a, char b)
5+
{
6+
return (a - b);
7+
}
8+
9+
char c;
10+
11+
void
12+
bar(signed char a, signed int b)
13+
{
14+
}
15+
16+
struct e {
17+
double c;
18+
char b;
19+
int a;
20+
};
21+
22+
struct e f;

diff/ld/Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Test a bug where different sized structures weren't diffing properly
3+
#
4+
5+
CTFDIFF = ctfdiff
6+
CFLAGS = -g -Werror
7+
CC = gcc
8+
RM = rm -f
9+
10+
all: a.ctf b.ctf
11+
12+
%.ctf: %.o
13+
$(CTFCONVERT)-altexec -L VERSION -o $@ $<
14+
15+
%.o: %.c
16+
$(CC) $(CFLAGS) -c $< -o $@
17+
18+
clobber:
19+
$(RM) -f *.o *.ctf

diff/ld/a.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
typedef unsigned long ulong_t;
2+
typedef ulong_t size_t;
3+
typedef size_t foo_t;
4+
5+
foo_t a;

diff/ld/b.c

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
typedef unsigned long size_t;
2+
typedef size_t foo_t;
3+
4+
foo_t a;

empty.c

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
struct foo;

enum.c

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
enum foo {
2+
HELLO,
3+
WORLD
4+
};
5+
6+
enum bar {
7+
CELES = 1,
8+
TERRA = 2,
9+
EDGAR = 3,
10+
SABIN = 4,
11+
KEFKA = -1
12+
};
13+
14+
typedef enum bar bar_t;

extern.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct foo;
2+
3+
struct bar {
4+
struct foo *prev;
5+
struct foo *next;
6+
int forward;
7+
};
8+
9+
struct bar a;

file.c

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <stdio.h>
2+
3+
FILE *foo;

float.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <math.h>
2+
#include <complex.h>
3+
4+
/*
5+
* GCC unfortuantely doesn't support imaginary types.
6+
*/
7+
8+
float a;
9+
double b;
10+
long double c;
11+
float d = 1I;
12+
double e = 2I;
13+
long double f = 3I;
14+
float complex g;
15+
double complex h;
16+
long double complex i;

fptr.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
typedef int (foo_t)(void *, const char *);
2+
3+
typedef void (*bar_t)(void *, ...);
4+
5+
typedef void (baz_t)(void);
6+
7+
int
8+
mumble(foo_t *a, bar_t b)
9+
{
10+
return ((int)a - (int)b);
11+
}

func.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
struct s {
2+
int s_int;
3+
};
4+
5+
void
6+
foo(void)
7+
{
8+
}
9+
10+
int
11+
bar(void)
12+
{
13+
return (42);
14+
}
15+
16+
int
17+
baz(int a, float b, long c)
18+
{
19+
return (a + (int)b + c);
20+
}
21+
22+
int
23+
var(int a, ...)
24+
{
25+
return (a);
26+
}
27+
28+
struct s *
29+
mumble(struct s *s)
30+
{
31+
return (s);
32+
}

int.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
char a;
2+
unsigned char b;
3+
signed char c;
4+
5+
short d;
6+
unsigned short e;
7+
signed short f;
8+
9+
int g;
10+
unsigned int h;
11+
signed int i;
12+
13+
long j;
14+
unsigned long k;
15+
signed long l;
16+
17+
long long m;
18+
unsigned long long n;
19+
signed long long o;

int.ctf.nodedup

2.36 KB
Binary file not shown.

libc-time.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Simulate the conversion failure from lib/libc/port/gen/time_data.c
3+
*/
4+
5+
const int __mon_lengths[2][12] = { };
6+
7+
const int __year_lengths[2] = { 365, 366 };
8+
const int __yday_to_month[12] = {0, 31, 59, 90, 120, 151, 181, 212,
9+
243, 273, 304, 334};
10+
const int __lyday_to_month[12] = {0, 31, 60, 91, 121, 152, 182, 213,
11+
244, 274, 305, 335};

merge/dup/Makefile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# Test a bug where if we have two different structs in an object file
3+
# with different names that we don't end up merging them correctly.
4+
#
5+
6+
CTFCONVERT = ctfconvert
7+
CVTFLAGS = -L VERSION
8+
CTFMERGE = ctfmerge
9+
MRGFLAGS = -j1 -t -f -L VERSION
10+
CFLAGS = -g -Werror
11+
CC = gcc
12+
RM = rm -f
13+
14+
PROG = test
15+
CONVOBJS = a.ctf b.ctf c.ctf
16+
OBJS = $(CONVOBJS:%.ctf=%.o)
17+
18+
$(PROG): $(CONVOBJS)
19+
$(CC) $(CFLAGS) -o $@ $(OBJS)
20+
$(CTFMERGE) $(MRGFLAGS) -o $@ $(CONVOBJS)
21+
22+
%.o: %.c
23+
$(CC) $(CFLAGS) -c $< -o $@
24+
25+
%.ctf: %.o
26+
$(CTFCONVERT)-altexec $(CVTFLAGS) -o $@ $<
27+
28+
clobber:
29+
$(RM) $(PROG) $(CONVOBJS) $(OBJS)

merge/dup/a.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
typedef struct foo {
2+
int bar;
3+
int baz;
4+
} foo_t;
5+
6+
foo_t a;

merge/dup/b.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
typedef struct foo {
2+
int bar;
3+
int baz;
4+
char blah;
5+
} foo_t;
6+
7+
foo_t b;

merge/dup/c.c

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
typedef struct foo foo_t;
2+
extern foo_t *c;
3+
4+
int
5+
main(void)
6+
{
7+
return (0);
8+
}

packstruct.c

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct unpacked {
2+
char a;
3+
long b;
4+
};
5+
6+
#pragma pack(1)
7+
struct packed {
8+
char a;
9+
long b;
10+
};
11+
#pragma pack()
12+
13+
struct unpacked a;
14+
struct packed b;

0 commit comments

Comments
 (0)