Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions filters/80-elf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ BIN_DIRS=(

filter_elf() {
local _opts=()
if ! bool "$ABSTRIP"; then
if bool "$ABSTRIP"; then
_opts+=('-s')
else
abinfo 'Not stripping ELF binaries as requested.'
_opts+=('-r')
elif ! bool "$ABSPLITDBG"; then
abinfo 'Not splitting ELF binaries as requested.'
_opts+=('-x')
fi
if bool "$ABSPLITDBG"; then
_opts+=('-d')
else
abinfo 'Not splitting ELF binaries as requested.'
fi

local _elf_path=()
Expand Down
5 changes: 1 addition & 4 deletions filters/81-pdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ filter_pdb() {
for f in "$i"/**/*.@(pdb|dbg); do
if bool "$ABSPLITDBG"; then
path="${f#"$PKGDIR"}"
abinfo "Saving Program Database file $f ..."
abinfo "Moving Program Database file $f ..."
mkdir -p "$(dirname "$SYMDIR"/"$path")"
mv "$f" "$SYMDIR"/"$path"
elif bool "$ABSTRIP"; then
abinfo "Dropping Program Database file $f ..."
rm "$f"
fi
done
fi
Expand Down
2 changes: 1 addition & 1 deletion lib/default-defines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ABCONFIGHACK=yes # Use config.{sub,guess} replacement for newer architectures?
NOCARGOAUDIT=no # Audit Cargo (Rust) dependencies?
NONPMAUDIT=no # Audit NPM dependencies?
ABUSECMAKEBUILD=yes # Use cmake build for cmake* ABTYPEs?
ABSPLITDBG=yes # Automatically compile with -g and produce debug symbol package ($PKGNAME-dbg)?
ABSPLITDBG=yes # Automatically compile with -g and split out a debug symbol package ($PKGNAME-dbg)?
ABBUILDDEPONLY=no # Avoid installing runtime dependencies when building?
ABPATCHLAX=no # Disallow fuzzy patching
ABSPIRAL=yes # Enable spiral provides generation
Expand Down
115 changes: 73 additions & 42 deletions native/abnativeelf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,17 @@ int elf_copy_debug_symbols(const char *src_path, const char *dst_path,
symbols.insert(result.needed_libs.begin(), result.needed_libs.end());
}

if (flags & AB_ELF_CHECK_ONLY)
bool split_debug = flags & AB_ELF_SPLIT_DEBUG;
bool strip_symbols = flags & AB_ELF_STRIP_SYMBOLS;
bool use_eu_strip = flags & AB_ELF_USE_EU_STRIP;
bool save_with_path = flags & AB_ELF_SAVE_WITH_PATH;

if (!split_debug && !strip_symbols)
return 0;

if (!result.has_debug_info) {
// no debug info, strip only
flags |= AB_ELF_STRIP_ONLY;
// no debug info, don't split
split_debug = false;
}

switch (result.bin_type) {
Expand All @@ -702,54 +707,63 @@ int elf_copy_debug_symbols(const char *src_path, const char *dst_path,
// skip and also notify the caller
return 1;
case BinaryType::Static:
// skip static library
flags |= AB_ELF_STRIP_ONLY;
// Debug symbol splitting is unsupported for static libraries.
split_debug = false;
// eu-strip can not handle static libraries
flags &= ~AB_ELF_USE_EU_STRIP;
args.emplace_back("-R");
args.emplace_back(".gnu.lto*");
args.emplace_back("--strip-debug");
extra_args.emplace_back("--enable-deterministic-archives");
use_eu_strip = false;
if (strip_symbols) {
args.emplace_back("-R");
args.emplace_back(".gnu.lto*");
args.emplace_back("--strip-debug");
extra_args.emplace_back("--enable-deterministic-archives");
}
break;
case BinaryType::Executable:
// strip all symbols
args.emplace_back("-s");
if (strip_symbols) {
// strip all symbols
args.emplace_back("-s");
}
break;
case BinaryType::Relocatable:
// disable debug symbol saving for relocatables
split_debug = false;
// also uses GNU binutils strip for compatibility
flags |= AB_ELF_STRIP_ONLY;
flags &= ~AB_ELF_USE_EU_STRIP;
args.emplace_back("--strip-debug");
extra_args.emplace_back("--enable-deterministic-archives");
use_eu_strip = false;
if (strip_symbols) {
args.emplace_back("--strip-debug");
extra_args.emplace_back("--enable-deterministic-archives");
}
break;
case BinaryType::Dynamic:
case BinaryType::KernelObject:
extra_args.emplace_back("--strip-unneeded");
if (strip_symbols) {
extra_args.emplace_back("--strip-unneeded");
}
break;
}

fs::path final_path;
if (flags & AB_ELF_STRIP_ONLY) {
if (split_debug && strip_symbols) {
get_logger()->info(fmt::format(
"Splitting debug symbols and stripping symbols from {0}", src_path));
} else if (split_debug) {
get_logger()->info(
fmt::format("Stripping debug symbols from {0}", src_path));
fmt::format("Splitting debug symbols from {0}", src_path));
} else if (strip_symbols) {
get_logger()->info(fmt::format("Stripping symbols from {0}", src_path));
} else {
get_logger()->info(
fmt::format("Saving and stripping debug symbols from {0}", src_path));
if (!result.has_debug_info) {
get_logger()->warning(
fmt::format("No debug symbols found in {0}", src_path));
return -3;
}
return 0;
}

if (result.build_id.empty() && !(flags & AB_ELF_SAVE_WITH_PATH)) {
fs::path final_path;
if (split_debug) {
if (result.build_id.empty() && !save_with_path) {
// For binaries without build-id, save with path
flags |= AB_ELF_SAVE_WITH_PATH;
save_with_path = true;
get_logger()->warning(fmt::format(
"No build id found in {0}. Saving with relative path", src_path));
}

if (flags & AB_ELF_SAVE_WITH_PATH) {
if (save_with_path) {
final_path = fs::path{dst_path} / fs::path{src_path}.filename();
get_logger()->debug(fmt::format("Saving to {0}", final_path.string()));
} else {
Expand All @@ -760,9 +774,18 @@ int elf_copy_debug_symbols(const char *src_path, const char *dst_path,
fs::create_directories(final_prefix);
}

if (flags & AB_ELF_USE_EU_STRIP) {
if (use_eu_strip) {
if (!strip_symbols) {
const char *eu_strip_args[] = {
"eu-strip", "--strip-debug", "--reloc-debug-sections",
"-f", final_path.c_str(), src_path,
nullptr};
return forked_execvp("eu-strip",
const_cast<char *const *>(eu_strip_args));
}

args[0] = "eu-strip";
if (!(flags & AB_ELF_STRIP_ONLY)) {
if (split_debug) {
args.emplace_back("--reloc-debug-sections");
args.emplace_back("-f");
args.emplace_back(final_path.c_str());
Expand All @@ -771,21 +794,29 @@ int elf_copy_debug_symbols(const char *src_path, const char *dst_path,
args.emplace_back(nullptr);
return forked_execvp("eu-strip", const_cast<char *const *>(args.data()));
}
if (!(flags & AB_ELF_STRIP_ONLY)) {
const auto path = final_path.string();
const char *args[] = {

if (split_debug) {
const char *objcopy_args[] = {
"objcopy", "--only-keep-debug", "--compress-debug-sections=zstd",
src_path, path.c_str(), nullptr};
int ret = forked_execvp("objcopy", const_cast<char *const *>(args));
src_path, final_path.c_str(), nullptr};
const int ret =
forked_execvp("objcopy", const_cast<char *const *>(objcopy_args));
if (ret != 0) {
return ret;
}
}
args[0] = "strip";
std::copy(extra_args.begin(), extra_args.end(), std::back_inserter(args));
args.emplace_back(src_path);
args.emplace_back(nullptr);
return forked_execvp("strip", const_cast<char *const *>(args.data()));

if (strip_symbols) {
args[0] = "strip";
std::copy(extra_args.begin(), extra_args.end(), std::back_inserter(args));
args.emplace_back(src_path);
args.emplace_back(nullptr);
return forked_execvp("strip", const_cast<char *const *>(args.data()));
}

const char *strip_debug_args[] = {"strip", "--strip-debug", src_path,
nullptr};
return forked_execvp("strip", const_cast<char *const *>(strip_debug_args));
}

int elf_copy_to_symdir(const char *src_path, const char *dst_path,
Expand Down
10 changes: 5 additions & 5 deletions native/abnativeelf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ template <typename T> class GuardedSet {
std::unordered_set<T> m_set;
};

constexpr int AB_ELF_STRIP_ONLY = 1 << 0;
constexpr int AB_ELF_USE_EU_STRIP = 1 << 1;
constexpr int AB_ELF_FIND_SO_DEPS = 1 << 2;
constexpr int AB_ELF_CHECK_ONLY = 1 << 3;
constexpr int AB_ELF_SPLIT_DEBUG = 1 << 0;
constexpr int AB_ELF_STRIP_SYMBOLS = 1 << 1;
constexpr int AB_ELF_USE_EU_STRIP = 1 << 2;
constexpr int AB_ELF_FIND_SO_DEPS = 1 << 3;
constexpr int AB_ELF_SAVE_WITH_PATH = 1 << 4;
constexpr int AB_ELF_FIND_SONAMES = 1 << 5;

Expand All @@ -81,6 +81,6 @@ int elf_copy_debug_symbols_parallel(const std::vector<std::string> &directories,
const char *dst_path,
std::unordered_set<std::string> &so_deps,
std::unordered_set<std::string> &sonames,
int flags = AB_ELF_USE_EU_STRIP);
int flags);
const std::unordered_set<std::string>
aosc_arch_to_debian_arch_suffix(const char *arch_name);
30 changes: 19 additions & 11 deletions native/abnativefunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,11 @@ static int abelf_elf_copy_to_symdir(WORD_LIST *list) {
/**
* Copy debug symbols for one specific file specified:
* @param list arguments of the following form:
* <-flags> <source directories> <destination directory>
* <-flags> <source file> <destination directory>
* -d: split debug symbols
* -s: strip symbols
* -e: use eu-strip
* -p: save debug symbols by filename instead of build ID
* @return command status code:
* 0 - success
* 1 - invalid flags
Expand All @@ -798,13 +802,13 @@ static int abelf_copy_dbg(WORD_LIST *list) {
int flags = AB_ELF_FIND_SO_DEPS;
reset_internal_getopt();
int opt = 0;
while ((opt = internal_getopt(list, const_cast<char *>("exrp"))) != -1) {
while ((opt = internal_getopt(list, const_cast<char *>("desp"))) != -1) {
switch (opt) {
case 'x':
flags |= AB_ELF_STRIP_ONLY;
case 'd':
flags |= AB_ELF_SPLIT_DEBUG;
break;
case 'r':
flags |= AB_ELF_CHECK_ONLY;
case 's':
flags |= AB_ELF_STRIP_SYMBOLS;
break;
case 'e':
flags |= AB_ELF_USE_EU_STRIP;
Expand Down Expand Up @@ -847,6 +851,10 @@ static void ab_set_to_bash_array(const char *varname,
* Copy debug symbols for all files specified:
* @param list arguments of the following form:
* <-flags> <source directories> <destination directory>
* -d: split debug symbols
* -s: strip symbols
* -e: use eu-strip
* -p: save debug symbols by filename instead of build ID
* @return command status code:
* 0 - success
* 1 - invalid flags
Expand All @@ -860,13 +868,13 @@ static int abelf_copy_dbg_parallel(WORD_LIST *list) {

reset_internal_getopt();
int opt = 0;
while ((opt = internal_getopt(list, const_cast<char *>("exrp"))) != -1) {
while ((opt = internal_getopt(list, const_cast<char *>("desp"))) != -1) {
switch (opt) {
case 'x':
flags |= AB_ELF_STRIP_ONLY;
case 'd':
flags |= AB_ELF_SPLIT_DEBUG;
break;
case 'r':
flags |= AB_ELF_CHECK_ONLY;
case 's':
flags |= AB_ELF_STRIP_SYMBOLS;
break;
case 'e':
flags |= AB_ELF_USE_EU_STRIP;
Expand Down
6 changes: 0 additions & 6 deletions proc/01-core-defines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ if [ "$ABHOST" != "noarch" ] ; then
unset last_status chk_op
fi

if ! bool "$ABSTRIP" && bool "$ABSPLITDBG"; then
abwarn "QA: ELF stripping is turned OFF."
abwarn " Won't package debug symbols as they are shipped in ELF themselves."
ABSPLITDBG=0
fi

if [[ $ABHOST == noarch ]]; then
abinfo "Architecture-agnostic (noarch) package detected, disabling -dbg package split ..."
ABSPLITDBG=0
Expand Down
Loading