diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/common_bufsiz.c | 74 | ||||
-rw-r--r-- | libbb/messages.c | 5 |
2 files changed, 74 insertions, 5 deletions
diff --git a/libbb/common_bufsiz.c b/libbb/common_bufsiz.c new file mode 100644 index 000000000..c16c361c9 --- /dev/null +++ b/libbb/common_bufsiz.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Utility routines. | ||
4 | * | ||
5 | * Copyright (C) 2016 Denys Vlasenko | ||
6 | * | ||
7 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
8 | */ | ||
9 | //config:config FEATURE_USE_BSS_TAIL | ||
10 | //config: bool "Use the end of BSS page" | ||
11 | //config: default n | ||
12 | //config: help | ||
13 | //config: Attempt to reclaim a small unused part of BSS. | ||
14 | //config: | ||
15 | //config: Executables have the following parts: | ||
16 | //config: = read-only executable code and constants, also known as "text" | ||
17 | //config: = read-write data | ||
18 | //config: = non-initialized (zeroed on demand) data, also known as "bss" | ||
19 | //config: | ||
20 | //config: At link time, "text" is padded to a full page. At runtime, all "text" | ||
21 | //config: pages are mapped RO and executable. | ||
22 | //config: "Data" starts on the next page boundary, but is not padded | ||
23 | //config: to a full page at the end. "Bss" starts wherever "data" ends. | ||
24 | //config: At runtime, "data" pages are mapped RW and they are file-backed | ||
25 | //config: (this includes a small portion of "bss" which may live in the last | ||
26 | //config: partial page of "data"). | ||
27 | //config: Pages which are fully in "bss" are mapped to anonymous memory. | ||
28 | //config: | ||
29 | //config: "Bss" end is usually not page-aligned. There is an unused space | ||
30 | //config: in the last page. Linker marks its start with the "_end" symbol. | ||
31 | //config: | ||
32 | //config: This option will attempt to use that space for bb_common_bufsiz1[] | ||
33 | //config: array. If it fits after _end, it will be used, and COMMON_BUFSIZE | ||
34 | //config: will be enlarged from its guaranteed minimum size of 1 kbyte. | ||
35 | //config: This may require recompilation a second time, since value of _end | ||
36 | //config: is known only after final link. | ||
37 | //config: | ||
38 | //config: If you are getting a build error like this: | ||
39 | //config: appletlib.c:(.text.main+0xd): undefined reference to '_end' | ||
40 | //config: disable this option. | ||
41 | |||
42 | //kbuild:lib-y += common_bufsiz.o | ||
43 | |||
44 | #include "libbb.h" | ||
45 | #include "common_bufsiz.h" | ||
46 | |||
47 | #if !ENABLE_FEATURE_USE_BSS_TAIL | ||
48 | |||
49 | /* We use it for "global" data via *(struct global*)bb_common_bufsiz1. | ||
50 | * Since gcc insists on aligning struct global's members, it would be a pity | ||
51 | * (and an alignment fault on some CPUs) to mess it up. */ | ||
52 | char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long)); | ||
53 | |||
54 | #else | ||
55 | |||
56 | # ifndef setup_common_bufsiz | ||
57 | /* | ||
58 | * It is not a "((void)0)" macro. It means we have to provide this function. | ||
59 | */ | ||
60 | char* bb_common_bufsiz1; | ||
61 | char* setup_common_bufsiz(void) | ||
62 | { | ||
63 | if (!bb_common_bufsiz1) | ||
64 | bb_common_bufsiz1 = xzalloc(COMMON_BUFSIZE); | ||
65 | return bb_common_bufsiz1; | ||
66 | } | ||
67 | # else | ||
68 | # ifndef bb_common_bufsiz1 | ||
69 | /* bb_common_bufsiz1[] is not aliased to _end[] */ | ||
70 | char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long)); | ||
71 | # endif | ||
72 | # endif | ||
73 | |||
74 | #endif | ||
diff --git a/libbb/messages.c b/libbb/messages.c index 23e440bcd..cb0836de8 100644 --- a/libbb/messages.c +++ b/libbb/messages.c | |||
@@ -59,8 +59,3 @@ const char bb_path_wtmp_file[] ALIGN1 = | |||
59 | # error unknown path to wtmp file | 59 | # error unknown path to wtmp file |
60 | # endif | 60 | # endif |
61 | #endif | 61 | #endif |
62 | |||
63 | /* We use it for "global" data via *(struct global*)&bb_common_bufsiz1. | ||
64 | * Since gcc insists on aligning struct global's members, it would be a pity | ||
65 | * (and an alignment fault on some CPUs) to mess it up. */ | ||
66 | char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long)); | ||