Skip to content

Commit f22a182

Browse files
committed
abnativeelf: always mark static libraries for stripping ...
... and also fix the logging output to show no debug symbol is saved in this case
1 parent 0aed934 commit f22a182

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

native/abnativeelf.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,15 @@ const AOSCArch detect_architecture(Elf *elf_file, GElf_Ehdr &elf_ehdr,
390390
static ELFParseResult identify_binary_data(const char *data,
391391
const size_t size) {
392392
ELFParseResult result{};
393-
if (size >= 8 && memcmp(data, ar_magic.data(), ar_magic.size()) == 0) {
394-
result.bin_type = BinaryType::Static;
395-
return result;
396-
} else if (size >= 8 &&
397-
memcmp(data, ar_thin_magic.data(), ar_thin_magic.size()) == 0) {
393+
const bool is_static_library =
394+
(size >= 8 && memcmp(data, ar_magic.data(), ar_magic.size()) == 0) ||
395+
(size >= 8 &&
396+
memcmp(data, ar_thin_magic.data(), ar_thin_magic.size()) == 0);
397+
if (is_static_library) {
398398
result.bin_type = BinaryType::Static;
399+
// Let's assume static libraries have debug info
400+
// as we can't easily check them
401+
result.has_debug_info = true;
399402
return result;
400403
} else if (size >= 4 &&
401404
memcmp(data, llvm_bc_magic.data(), llvm_bc_magic.size()) == 0) {
@@ -666,31 +669,32 @@ int elf_copy_debug_symbols(const char *src_path, const char *dst_path,
666669
break;
667670
}
668671

669-
get_logger()->info(
670-
fmt::format("Saving and stripping debug symbols from {0}", src_path));
671-
672-
if (!result.has_debug_info) {
673-
get_logger()->warning(
674-
fmt::format("No debug symbols found in {0}", src_path));
675-
return -3;
676-
}
677-
678-
if (result.build_id.empty() && !(flags & AB_ELF_SAVE_WITH_PATH)) {
679-
// For binaries without build-id, save with path
680-
flags |= AB_ELF_SAVE_WITH_PATH;
681-
get_logger()->warning(fmt::format(
682-
"No build id found in {0}. Saving with relative path", src_path));
683-
}
684-
685672
fs::path final_path;
686-
if (flags & AB_ELF_SAVE_WITH_PATH) {
687-
final_path = fs::path{dst_path} / fs::path{src_path}.filename();
688-
get_logger()->debug(fmt::format("Saving to {0}", final_path.string()));
673+
if (flags & AB_ELF_STRIP_ONLY) {
674+
get_logger()->info(
675+
fmt::format("Stripping debug symbols from {0}", src_path));
689676
} else {
690-
final_path = get_filename_from_build_id(result.build_id, dst_path);
691-
}
677+
get_logger()->info(
678+
fmt::format("Saving and stripping debug symbols from {0}", src_path));
679+
if (!result.has_debug_info) {
680+
get_logger()->warning(
681+
fmt::format("No debug symbols found in {0}", src_path));
682+
return -3;
683+
}
692684

693-
if (!(flags & AB_ELF_STRIP_ONLY)) {
685+
if (result.build_id.empty() && !(flags & AB_ELF_SAVE_WITH_PATH)) {
686+
// For binaries without build-id, save with path
687+
flags |= AB_ELF_SAVE_WITH_PATH;
688+
get_logger()->warning(fmt::format(
689+
"No build id found in {0}. Saving with relative path", src_path));
690+
}
691+
692+
if (flags & AB_ELF_SAVE_WITH_PATH) {
693+
final_path = fs::path{dst_path} / fs::path{src_path}.filename();
694+
get_logger()->debug(fmt::format("Saving to {0}", final_path.string()));
695+
} else {
696+
final_path = get_filename_from_build_id(result.build_id, dst_path);
697+
}
694698
// No need to create directories if we aren't going to save symbol files
695699
const fs::path final_prefix = final_path.parent_path();
696700
fs::create_directories(final_prefix);

0 commit comments

Comments
 (0)