Skip to content

Commit

Permalink
dSupport --dynamic-list-data
Browse files Browse the repository at this point in the history
Fixes #1320
  • Loading branch information
rui314 committed Aug 1, 2024
1 parent 982f071 commit dd8d971
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions elf/cmdline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1304,6 +1305,8 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &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, "<command line>"});
} else if (read_arg("export-dynamic-symbol-list")) {
Expand Down
1 change: 1 addition & 0 deletions elf/mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions elf/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,9 @@ static bool should_export(Context<E> &ctx, Symbol<E> &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<E> *)sym.file)->exclude_libs;
return ctx.arg.export_dynamic;
Expand Down
13 changes: 13 additions & 0 deletions test/elf/dynamic-list-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
. $(dirname $0)/common.inc

cat <<EOF | $CC -o $t/a.o -c -xc -
int foo = 5;
void bar() {}
int main() {}
EOF

$CC -B. -o $t/exe $t/a.o -Wl,-dynamic-list-data
readelf -W --dyn-syms $t/exe > $t/log
grep -wq foo $t/log
! grep -wq bar $t/log || false

0 comments on commit dd8d971

Please sign in to comment.