dpkg: reduce bss usage by ~130 kbytes (yes, kilobytes!)
at the cost of ~100 bytes of text. Improves friendliness to nommu systems. (Dunno whether nommu people ever use dpkg, though...)
This commit is contained in:
parent
06b543b217
commit
57308afb5b
@ -42,7 +42,6 @@
|
|||||||
* I estimate it should be at least 50% bigger than PACKAGE_HASH_PRIME,
|
* I estimate it should be at least 50% bigger than PACKAGE_HASH_PRIME,
|
||||||
* as there a lot of duplicate version numbers */
|
* as there a lot of duplicate version numbers */
|
||||||
#define NAME_HASH_PRIME 16381
|
#define NAME_HASH_PRIME 16381
|
||||||
static char *name_hashtable[NAME_HASH_PRIME + 1];
|
|
||||||
|
|
||||||
/* PACKAGE_HASH_PRIME, Maximum number of unique packages,
|
/* PACKAGE_HASH_PRIME, Maximum number of unique packages,
|
||||||
* It must not be smaller than STATUS_HASH_PRIME,
|
* It must not be smaller than STATUS_HASH_PRIME,
|
||||||
@ -66,7 +65,6 @@ typedef struct common_node_s {
|
|||||||
unsigned int num_of_edges:14;
|
unsigned int num_of_edges:14;
|
||||||
edge_t **edge;
|
edge_t **edge;
|
||||||
} common_node_t;
|
} common_node_t;
|
||||||
static common_node_t *package_hashtable[PACKAGE_HASH_PRIME + 1];
|
|
||||||
|
|
||||||
/* Currently it doesnt store packages that have state-status of not-installed
|
/* Currently it doesnt store packages that have state-status of not-installed
|
||||||
* So it only really has to be the size of the maximum number of packages
|
* So it only really has to be the size of the maximum number of packages
|
||||||
@ -76,7 +74,11 @@ typedef struct status_node_s {
|
|||||||
unsigned int package:14; /* has to fit PACKAGE_HASH_PRIME */
|
unsigned int package:14; /* has to fit PACKAGE_HASH_PRIME */
|
||||||
unsigned int status:14; /* has to fit STATUS_HASH_PRIME */
|
unsigned int status:14; /* has to fit STATUS_HASH_PRIME */
|
||||||
} status_node_t;
|
} status_node_t;
|
||||||
static status_node_t *status_hashtable[STATUS_HASH_PRIME + 1];
|
|
||||||
|
/* Were statically declared here, but such a big bss is nommu-unfriendly */
|
||||||
|
static char **name_hashtable; /* [NAME_HASH_PRIME + 1] */
|
||||||
|
static common_node_t **package_hashtable; /* [PACKAGE_HASH_PRIME + 1] */
|
||||||
|
static status_node_t **status_hashtable; /* [STATUS_HASH_PRIME + 1] */
|
||||||
|
|
||||||
/* Even numbers are for 'extras', like ored dependencies or null */
|
/* Even numbers are for 'extras', like ored dependencies or null */
|
||||||
enum edge_type_e {
|
enum edge_type_e {
|
||||||
@ -492,7 +494,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
|
|||||||
else if (strncmp(version, ">=", offset_ch) == 0) {
|
else if (strncmp(version, ">=", offset_ch) == 0) {
|
||||||
edge->operator = VER_MORE_EQUAL;
|
edge->operator = VER_MORE_EQUAL;
|
||||||
} else {
|
} else {
|
||||||
bb_error_msg_and_die("Illegal operator");
|
bb_error_msg_and_die("illegal operator");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* skip to start of version numbers */
|
/* skip to start of version numbers */
|
||||||
@ -960,11 +962,11 @@ static void write_status_file(deb_file_t **deb_file)
|
|||||||
xstat("/var/lib/dpkg/status", &stat_buf);
|
xstat("/var/lib/dpkg/status", &stat_buf);
|
||||||
/* Its ok if renaming the status file fails because status
|
/* Its ok if renaming the status file fails because status
|
||||||
* file doesnt exist, maybe we are starting from scratch */
|
* file doesnt exist, maybe we are starting from scratch */
|
||||||
bb_error_msg("No status file found, creating new one");
|
bb_error_msg("no status file found, creating new one");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status") == -1) {
|
if (rename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status") == -1) {
|
||||||
bb_error_msg_and_die("DANGER: Couldnt create status file, you need to manually repair your status file");
|
bb_error_msg_and_die("DANGER: Cannot create status file, you need to manually repair your status file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1066,7 +1068,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
bb_error_msg_and_die("Package %s conflicts with %s",
|
bb_error_msg_and_die("package %s conflicts with %s",
|
||||||
name_hashtable[package_node->name],
|
name_hashtable[package_node->name],
|
||||||
name_hashtable[package_edge->name]);
|
name_hashtable[package_edge->name]);
|
||||||
}
|
}
|
||||||
@ -1136,7 +1138,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
|||||||
* EDGE_PRE_DEPENDS == OR_PRE_DEPENDS -1
|
* EDGE_PRE_DEPENDS == OR_PRE_DEPENDS -1
|
||||||
*/
|
*/
|
||||||
if (root_of_alternatives && package_edge->type != root_of_alternatives->type - 1)
|
if (root_of_alternatives && package_edge->type != root_of_alternatives->type - 1)
|
||||||
bb_error_msg_and_die("Fatal error. Package dependencies corrupt: %d != %d - 1",
|
bb_error_msg_and_die("fatal error, package dependencies corrupt: %d != %d - 1",
|
||||||
package_edge->type, root_of_alternatives->type);
|
package_edge->type, root_of_alternatives->type);
|
||||||
|
|
||||||
if (package_hashtable[package_num] != NULL)
|
if (package_hashtable[package_num] != NULL)
|
||||||
@ -1147,7 +1149,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
|||||||
|
|
||||||
while ((provider = search_for_provides(package_edge->name, provider)) > -1) {
|
while ((provider = search_for_provides(package_edge->name, provider)) > -1) {
|
||||||
if (package_hashtable[provider] == NULL) {
|
if (package_hashtable[provider] == NULL) {
|
||||||
printf("Have a provider but no package information for it\n");
|
puts("Have a provider but no package information for it");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result = !package_satisfies_dependency(provider, package_edge->type);
|
result = !package_satisfies_dependency(provider, package_edge->type);
|
||||||
@ -1162,14 +1164,14 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
|
|||||||
if (result && number_of_alternatives == 0) {
|
if (result && number_of_alternatives == 0) {
|
||||||
if (root_of_alternatives)
|
if (root_of_alternatives)
|
||||||
bb_error_msg_and_die(
|
bb_error_msg_and_die(
|
||||||
"Package %s %sdepends on %s, "
|
"package %s %sdepends on %s, "
|
||||||
"which cannot be satisfied",
|
"which cannot be satisfied",
|
||||||
name_hashtable[package_node->name],
|
name_hashtable[package_node->name],
|
||||||
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
||||||
name_hashtable[root_of_alternatives->name]);
|
name_hashtable[root_of_alternatives->name]);
|
||||||
else
|
else
|
||||||
bb_error_msg_and_die(
|
bb_error_msg_and_die(
|
||||||
"Package %s %sdepends on %s, which %s\n",
|
"package %s %sdepends on %s, which %s\n",
|
||||||
name_hashtable[package_node->name],
|
name_hashtable[package_node->name],
|
||||||
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
||||||
name_hashtable[package_edge->name],
|
name_hashtable[package_edge->name],
|
||||||
@ -1310,8 +1312,8 @@ static void list_packages(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf(" Name Version\n");
|
puts(" Name Version");
|
||||||
printf("+++-==============-==============\n");
|
puts("+++-==============-==============");
|
||||||
|
|
||||||
/* go through status hash, dereference package hash and finally strings */
|
/* go through status hash, dereference package hash and finally strings */
|
||||||
for (i=0; i<STATUS_HASH_PRIME+1; i++) {
|
for (i=0; i<STATUS_HASH_PRIME+1; i++) {
|
||||||
@ -1559,7 +1561,7 @@ static void unpack_package(deb_file_t *deb_file)
|
|||||||
/* Run the preinst prior to extracting */
|
/* Run the preinst prior to extracting */
|
||||||
if (run_package_script(package_name, "preinst") != 0) {
|
if (run_package_script(package_name, "preinst") != 0) {
|
||||||
/* when preinst returns exit code != 0 then quit installation process */
|
/* when preinst returns exit code != 0 then quit installation process */
|
||||||
bb_error_msg_and_die("subprocess pre-installation script returned error.");
|
bb_error_msg_and_die("subprocess pre-installation script returned error");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract data.tar.gz to the root directory */
|
/* Extract data.tar.gz to the root directory */
|
||||||
@ -1619,6 +1621,10 @@ int dpkg_main(int argc, char **argv)
|
|||||||
int status_num;
|
int status_num;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
name_hashtable = xzalloc(sizeof(name_hashtable[0]) * (NAME_HASH_PRIME + 1));
|
||||||
|
package_hashtable = xzalloc(sizeof(package_hashtable[0]) * (PACKAGE_HASH_PRIME + 1));
|
||||||
|
status_hashtable = xzalloc(sizeof(status_hashtable[0]) * (STATUS_HASH_PRIME + 1));
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "CF:ilPru")) != -1) {
|
while ((opt = getopt(argc, argv, "CF:ilPru")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'C': // equivalent to --configure in official dpkg
|
case 'C': // equivalent to --configure in official dpkg
|
||||||
@ -1682,13 +1688,13 @@ int dpkg_main(int argc, char **argv)
|
|||||||
init_archive_deb_control(archive_handle);
|
init_archive_deb_control(archive_handle);
|
||||||
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);
|
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);
|
||||||
if (deb_file[deb_count]->control_file == NULL) {
|
if (deb_file[deb_count]->control_file == NULL) {
|
||||||
bb_error_msg_and_die("Couldnt extract control file");
|
bb_error_msg_and_die("cannot extract control file");
|
||||||
}
|
}
|
||||||
deb_file[deb_count]->filename = xstrdup(argv[optind]);
|
deb_file[deb_count]->filename = xstrdup(argv[optind]);
|
||||||
package_num = fill_package_struct(deb_file[deb_count]->control_file);
|
package_num = fill_package_struct(deb_file[deb_count]->control_file);
|
||||||
|
|
||||||
if (package_num == -1) {
|
if (package_num == -1) {
|
||||||
bb_error_msg("Invalid control file in %s", argv[optind]);
|
bb_error_msg("invalid control file in %s", argv[optind]);
|
||||||
optind++;
|
optind++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1718,7 +1724,7 @@ int dpkg_main(int argc, char **argv)
|
|||||||
search_name_hashtable(argv[optind]),
|
search_name_hashtable(argv[optind]),
|
||||||
search_name_hashtable("ANY"), VER_ANY);
|
search_name_hashtable("ANY"), VER_ANY);
|
||||||
if (package_hashtable[deb_file[deb_count]->package] == NULL) {
|
if (package_hashtable[deb_file[deb_count]->package] == NULL) {
|
||||||
bb_error_msg_and_die("Package %s is uninstalled or unknown", argv[optind]);
|
bb_error_msg_and_die("package %s is uninstalled or unknown", argv[optind]);
|
||||||
}
|
}
|
||||||
package_num = deb_file[deb_count]->package;
|
package_num = deb_file[deb_count]->package;
|
||||||
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
|
status_num = search_status_hashtable(name_hashtable[package_hashtable[package_num]->name]);
|
||||||
@ -1728,14 +1734,14 @@ int dpkg_main(int argc, char **argv)
|
|||||||
if (dpkg_opt & dpkg_opt_remove) {
|
if (dpkg_opt & dpkg_opt_remove) {
|
||||||
if ((strcmp(name_hashtable[state_status], "not-installed") == 0) ||
|
if ((strcmp(name_hashtable[state_status], "not-installed") == 0) ||
|
||||||
(strcmp(name_hashtable[state_status], "config-files") == 0)) {
|
(strcmp(name_hashtable[state_status], "config-files") == 0)) {
|
||||||
bb_error_msg_and_die("%s is already removed.", name_hashtable[package_hashtable[package_num]->name]);
|
bb_error_msg_and_die("%s is already removed", name_hashtable[package_hashtable[package_num]->name]);
|
||||||
}
|
}
|
||||||
set_status(status_num, "deinstall", 1);
|
set_status(status_num, "deinstall", 1);
|
||||||
}
|
}
|
||||||
else if (dpkg_opt & dpkg_opt_purge) {
|
else if (dpkg_opt & dpkg_opt_purge) {
|
||||||
/* if package status is "conf-files" then its ok */
|
/* if package status is "conf-files" then its ok */
|
||||||
if (strcmp(name_hashtable[state_status], "not-installed") == 0) {
|
if (strcmp(name_hashtable[state_status], "not-installed") == 0) {
|
||||||
bb_error_msg_and_die("%s is already purged.", name_hashtable[package_hashtable[package_num]->name]);
|
bb_error_msg_and_die("%s is already purged", name_hashtable[package_hashtable[package_num]->name]);
|
||||||
}
|
}
|
||||||
set_status(status_num, "purge", 1);
|
set_status(status_num, "purge", 1);
|
||||||
}
|
}
|
||||||
@ -1748,7 +1754,7 @@ int dpkg_main(int argc, char **argv)
|
|||||||
/* Check that the deb file arguments are installable */
|
/* Check that the deb file arguments are installable */
|
||||||
if ((dpkg_opt & dpkg_opt_force_ignore_depends) != dpkg_opt_force_ignore_depends) {
|
if ((dpkg_opt & dpkg_opt_force_ignore_depends) != dpkg_opt_force_ignore_depends) {
|
||||||
if (!check_deps(deb_file, 0, deb_count)) {
|
if (!check_deps(deb_file, 0, deb_count)) {
|
||||||
bb_error_msg_and_die("Dependency check failed");
|
bb_error_msg_and_die("dependency check failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1780,6 +1786,7 @@ int dpkg_main(int argc, char **argv)
|
|||||||
|
|
||||||
write_status_file(deb_file);
|
write_status_file(deb_file);
|
||||||
|
|
||||||
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||||
for (i = 0; i < deb_count; i++) {
|
for (i = 0; i < deb_count; i++) {
|
||||||
free(deb_file[i]->control_file);
|
free(deb_file[i]->control_file);
|
||||||
free(deb_file[i]->filename);
|
free(deb_file[i]->filename);
|
||||||
@ -1802,6 +1809,10 @@ int dpkg_main(int argc, char **argv)
|
|||||||
free(status_hashtable[i]);
|
free(status_hashtable[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(EXIT_SUCCESS);
|
free(status_hashtable);
|
||||||
|
free(package_hashtable);
|
||||||
|
free(name_hashtable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
@ -4,4 +4,4 @@ printf "%9s %11s %9s %9s %s\n" "text+data" text+rodata rwdata bss filename
|
|||||||
find -name '*.o' | sed 's:^\./::' | xargs size | grep '^ *[0-9]' \
|
find -name '*.o' | sed 's:^\./::' | xargs size | grep '^ *[0-9]' \
|
||||||
| while read text data bss dec hex filename; do
|
| while read text data bss dec hex filename; do
|
||||||
printf "%9d %11d %9d %9d %s\n" $((text+data)) $text $data $bss "$filename"
|
printf "%9d %11d %9d %9d %s\n" $((text+data)) $text $data $bss "$filename"
|
||||||
done
|
done | sort -r
|
||||||
|
Loading…
Reference in New Issue
Block a user