This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINSTALL
139 lines (96 loc) · 4.59 KB
/
INSTALL
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Generic instructions
~~~~~~~~~~~~~~~~~~~~
Build sequence is similar to generic autotools packages:
./configure (...)
make
make DESTDIR=(...) install
Run "./configure help" to see possible options.
Alternatively, check config.mk and/or config.h.
Specifically, check INITCTL, INITTAB, LOGDIR in config.h,
compiler setup and installation directories in config.mk.
PIE issues / relocation errors / stack protector errors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Some distributions configure gcc with PIE and/or SSP enabled
by default. Depending on gcc version, PIE may break -static
builds with errors like this:
/usr/bin/ld: libc.a(sigaction.o): relocation R_X86_64_32S against `.text'
can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
In properly configured toolchains -static alone should fix this, but some
toolchains also need -fno-pie.
SSP may be enabled by default as well, resulting in error messages like this:
init.o: In function `setpasstime':
init.c:(.text+0x5e): undefined reference to `__stack_chk_fail'
SSP must be disabled as it will probably not work with the bundled libc
(and dietlibc, and possibly anything that's not system libc).
Cross-compiling
~~~~~~~~~~~~~~~
Set CC and AR in config.mk for your target architecture.
Alternatively, run configure --target=(toolchain-prefix).
sninit follows Linux kernel naming scheme, with CC for target executables
and HOSTCC for build system executables.
Packaging for small size
~~~~~~~~~~~~~~~~~~~~~~~~
Simple make install does not strip executables.
If you need stripped executable, run this instead:
make DESTDIR=(...) install-stripped
If you don't need man pages as well, use
make DESTDIR=(...) install-bin-stripped
Building with bundled libc
~~~~~~~~~~~~~~~~~~~~~~~~~~
sninit comes with a stripped-down, minimalistic subset of dietlibc
capable just enough to fit sninit demands.
Sample usage (cross-build for mips):
ARCH = mips
CC = mipsel-linux-gnu-gcc -march=mips2
CC will be called with -nostdinc -nostdlib so it does not matter
which libc, if any, it has in its sysroot.
Check libc/ subdirectories to see which architectures are supported
by bundled libc. For unsupported architectures, fall back to dietlibc
or perhaps system libc.
Using bundled libc may be more convenient, but provides little benefit
over *properly*configured* dietlibc in terms of executable size
(because it is mostly dietlibc, if perhaps re-written in some places).
Instead gives clear, uncluttered libc code for debugging.
Note properly configured dietlibc. Depending on target architecture,
default dietlibc configuration may add several kB of bloat.
See doc/dietlibc.txt
Building with dietlibc
~~~~~~~~~~~~~~~~~~~~~~
Recommended settings:
CC = diet gcc
or
CC = diet clang
Use "configure diet gcc" or "configure diet clang" respectively.
Dietlibc up to and including 0.33 does not provide ppoll(2) system call.
Either use sys_ppoll.c (indirect syscall, via syscall(2)), or patch dietlibc.
Because dietlibc implies static linkage and small executable size,
consider using sys_printf.c and sys_strerror.c. See comments in those files.
Size optimization (-Os) helps in most cases.
Building with musl
~~~~~~~~~~~~~~~~~~
Use CC = musl-gcc when building on non-musl system.
If musl-gcc complains about linux/*.h, you probably have no linux headers
in musl-gcc path. Symlink /usr/include/linux and /usr/include/asm to
$MUSL/include/linux and $MUSL/include/asm respectively.
For musl-based systems, no settings should be necessary.
Configure options: "musl-gcc" for non-native builds, "musl" for musl toolchains.
Building with glibc or uClibc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Both glibc and uclibc lack getdents(2), even thought it is a linux system call.
Use sys_getdents.c instead.
Link-time optimization
~~~~~~~~~~~~~~~~~~~~~~
To enable LTO, add -flto to CFLAGS and LDFLAGS, or alternatively use "lto"
keyword for configure. It should work with any libc.
LTO is generally harmless, but it requires support from cc/binutils, and its
effects are usually minor. Because of this, it is not enabled by default.
LTO does not work out-of-the-box with clang at this moment.
Rebuilding
~~~~~~~~~~
Run "make clean" before rebuilding with a different ARCH value
or with a different libc type. Those affect config.mk, and Makefile
does not track dependencies on config.mk
Use "make distclean" to remove all generated files including target executable.
Note however that config.h and config.mk are modified in place, there are no
autoconf-style config.h.in or config.mk.in, so distclean will not restore them.