summaryrefslogtreecommitdiff
path: root/sys/conf/makegap.sh
blob: 603d9ee2906ac718d02f74057bab7d07b8fd7729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh -

random_uniform() {
	local	_upper_bound

	if [[ $1 -gt 0 ]]; then
		_upper_bound=$(($1 - 1))
	else
		_upper_bound=0
	fi

	echo `jot -r 1 0 $_upper_bound 2>/dev/null`
}

umask 007

PAGE_SIZE=`sysctl -n hw.pagesize`
PAD=$1
GAPDUMMY=$2

RANDOM1=`random_uniform $((3 * PAGE_SIZE))`
RANDOM2=`random_uniform $PAGE_SIZE`
RANDOM3=`random_uniform $PAGE_SIZE`
RANDOM4=`random_uniform $PAGE_SIZE`
RANDOM5=`random_uniform $PAGE_SIZE`

cat > gap.link << __EOF__

PHDRS {
	text PT_LOAD FILEHDR PHDRS;
	rodata PT_LOAD;
	data PT_LOAD;
	bss PT_LOAD;
}

SECTIONS {
	.text : ALIGN($PAGE_SIZE) {
		LONG($PAD);
		. += $RANDOM1;
		. = ALIGN($PAGE_SIZE);
		endboot = .;
		PROVIDE (endboot = .);
		. = ALIGN($PAGE_SIZE);
		. += $RANDOM2;
		. = ALIGN(16);
		*(.text .text.*)
	} :text =$PAD

	.rodata : {
		LONG($PAD);
		. += $RANDOM3;
		. = ALIGN(16);
		*(.rodata .rodata.*)
	} :rodata =$PAD

	.data : {
		LONG($PAD);
		. = . + $RANDOM4;	/* fragment of page */
		. = ALIGN(16);
		*(.data .data.*)
	} :data =$PAD

	.bss : {
		. = . + $RANDOM5;	/* fragment of page */
		. = ALIGN(16);
		*(.bss .bss.*)
	} :bss
}
__EOF__

$LD $LDFLAGS -r gap.link $GAPDUMMY -o gap.o