From dd8d9714cb14213766372fe39ecb2e8c1fe4533f Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 1 Aug 2024 18:49:43 +0900 Subject: [PATCH] dSupport --dynamic-list-data Fixes https://github.com/rui314/mold/issues/1320 --- elf/cmdline.cc | 3 +++ elf/mold.h | 1 + elf/passes.cc | 3 +++ test/elf/dynamic-list-data.sh | 13 +++++++++++++ 4 files changed, 20 insertions(+) create mode 100755 test/elf/dynamic-list-data.sh diff --git a/elf/cmdline.cc b/elf/cmdline.cc index 70fd0bff28..a0d57ae715 100644 --- a/elf/cmdline.cc +++ b/elf/cmdline.cc @@ -93,6 +93,7 @@ inline const char helpmsg[] = R"( --execute-only Make executable segments unreadable --dp Ignored --dynamic-list=FILE Read a list of dynamic symbols (implies -Bsymbolic) + --dynamic-list-data Add data symbols to dynamic symbols --eh-frame-hdr Create .eh_frame_hdr section --no-eh-frame-hdr --exclude-libs LIB,LIB,.. Mark all symbols in given libraries as hidden @@ -1304,6 +1305,8 @@ std::vector parse_nonpositional_args(Context &ctx) { } else if (read_arg("dynamic-list")) { ctx.arg.Bsymbolic = BSYMBOLIC_ALL; append(ctx.dynamic_list_patterns, parse_dynamic_list(ctx, arg)); + } else if (read_arg("dynamic-list-data")) { + ctx.arg.dynamic_list_data = true; } else if (read_arg("export-dynamic-symbol")) { ctx.dynamic_list_patterns.push_back({arg, ""}); } else if (read_arg("export-dynamic-symbol-list")) { diff --git a/elf/mold.h b/elf/mold.h index 36bc321cee..3c5b5fba7e 100644 --- a/elf/mold.h +++ b/elf/mold.h @@ -1799,6 +1799,7 @@ struct Context { bool detach = true; bool discard_all = false; bool discard_locals = false; + bool dynamic_list_data = false; bool eh_frame_hdr = true; bool emit_relocs = false; bool enable_new_dtags = true; diff --git a/elf/passes.cc b/elf/passes.cc index 34baecc823..a751a10d66 100644 --- a/elf/passes.cc +++ b/elf/passes.cc @@ -1929,6 +1929,9 @@ static bool should_export(Context &ctx, Symbol &sym) { switch (sym.ver_idx) { case VER_NDX_UNSPECIFIED: + if (ctx.arg.dynamic_list_data) + if (u32 ty = sym.get_type(); ty != STT_FUNC && ty != STT_GNU_IFUNC) + return true; if (ctx.arg.shared) return !((ObjectFile *)sym.file)->exclude_libs; return ctx.arg.export_dynamic; diff --git a/test/elf/dynamic-list-data.sh b/test/elf/dynamic-list-data.sh new file mode 100755 index 0000000000..b76c613aea --- /dev/null +++ b/test/elf/dynamic-list-data.sh @@ -0,0 +1,13 @@ +#!/bin/bash +. $(dirname $0)/common.inc + +cat < $t/log +grep -wq foo $t/log +! grep -wq bar $t/log || false