PAKFIRE_BUILD_CLEANUP_FILES);
}
+static int __pakfire_build_post_check_stripped(
+ struct pakfire* pakfire, struct pakfire_file* file, void* data) {
+ struct pakfire_filelist* filelist = (struct pakfire_filelist*)data;
+ int r;
+
+ // Skip anything that isn't an ELF file
+ if (!pakfire_file_matches_class(file, PAKFIRE_FILE_ELF))
+ return 0;
+
+ // Collect all stripped files
+ if (pakfire_file_is_stripped(file)) {
+ r = pakfire_filelist_add(filelist, file);
+ if (r) {
+ ERROR(pakfire, "Could not add file to filelist: %m\n");
+ return r;
+ }
+ }
+
+ return 0;
+}
+
+static int pakfire_build_post_check_stripped(
+ struct pakfire_build* build, struct pakfire_filelist* filelist) {
+ return pakfire_build_post_process_files(build, filelist,
+ "Files lacking debugging information:",
+ __pakfire_build_post_check_stripped,
+ PAKFIRE_BUILD_ERROR_IF_NOT_EMPTY);
+}
+
static int __pakfire_build_remove_libtool_archives(
struct pakfire* pakfire, struct pakfire_file* file, void* data) {
struct pakfire_filelist* removees = (struct pakfire_filelist*)data;
goto ERROR;
}
+ // Check if binaries have been stripped
+ r = pakfire_build_post_check_stripped(build, filelist);
+ if (r)
+ goto ERROR;
+
// Remove any static libraries
r = pakfire_build_post_remove_static_libraries(build, filelist);
if (r)
// Run post build checks
r = pakfire_build_run_post_build_checks(build);
- if (r)
+ if (r) {
+ ERROR(build->pakfire, "Post build checks failed\n");
goto ERROR;
+ }
// Run post build scripts
r = pakfire_build_run_post_build_scripts(build);
return r;
}
+static int __pakfire_file_is_stripped(struct pakfire_file* file, Elf* elf, void* data) {
+ Elf_Scn* section = NULL;
+ GElf_Shdr shdr;
+
+ // Walk through all sections
+ for (;;) {
+ section = elf_nextscn(elf, section);
+ if (!section)
+ break;
+
+ // Fetch the section header
+ gelf_getshdr(section, &shdr);
+
+ switch (shdr.sh_type) {
+ // Break if we found the symbol table
+ case SHT_SYMTAB:
+ return 0;
+ }
+ }
+
+ // Not found
+ DEBUG(file->pakfire, "%s has no debug sections\n", file->path);
+
+ return 1;
+}
+
+int pakfire_file_is_stripped(struct pakfire_file* file) {
+ // Don't run this for non-ELF files
+ if (!pakfire_file_matches_class(file, PAKFIRE_FILE_ELF)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ return pakfire_file_open_elf(file, __pakfire_file_is_stripped, NULL);
+}
+
static int __pakfire_file_hardening_check_ssp(
struct pakfire_file* file, Elf* elf, void* data) {
Elf_Scn* section = NULL;