mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 09:57:18 +03:00
Revert "Re-submit b23c47ae6dbe285e02627803eac0604cfaaa1e78"
This reverts commit a70b1eb58b
because
it's too risky to include it into 1.4.0.
This commit is contained in:
parent
10c211f1ab
commit
da2f3fe12c
@ -4,7 +4,6 @@
|
||||
|
||||
#include "mold.h"
|
||||
|
||||
#include <tbb/concurrent_set.h>
|
||||
#include <tbb/concurrent_vector.h>
|
||||
#include <tbb/parallel_for_each.h>
|
||||
|
||||
@ -73,43 +72,8 @@ static void visit(Context<E> &ctx, InputSection<E> *isec,
|
||||
}
|
||||
}
|
||||
|
||||
// We synthesize `__start_foo` and `__stop_foo` symbols for section
|
||||
// `foo` if the section name is valid as a C identifier (i.e. it
|
||||
// doesn't start with a '.' and doesn't contain punctuations).
|
||||
//
|
||||
// Such references are implicit, so we need to handle them separately.
|
||||
// In this function, we scan all symbols and keep section `foo` if
|
||||
// there is `__start_foo` or `__stop_foo` symbol.
|
||||
template <typename E>
|
||||
void
|
||||
collect_start_stop_sections(Context<E> &ctx,
|
||||
tbb::concurrent_vector<InputSection<E> *> &rootset) {
|
||||
Timer t(ctx, "collect_start_stop_sections");
|
||||
|
||||
tbb::concurrent_set<std::string_view> set;
|
||||
|
||||
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
|
||||
for (Symbol<E> *sym : file->symbols)
|
||||
if (!sym->file)
|
||||
if (std::string_view s = sym->name();
|
||||
remove_prefix(s, "__start_") || remove_prefix(s, "__stop_"))
|
||||
set.insert(s);
|
||||
});
|
||||
|
||||
if (set.empty())
|
||||
return;
|
||||
|
||||
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
|
||||
for (std::unique_ptr<InputSection<E>> &isec : file->sections)
|
||||
if (isec && isec->is_alive && is_c_identifier(isec->name()) &&
|
||||
set.contains(isec->name()) && isec->is_visited.exchange(true))
|
||||
rootset.push_back(isec.get());
|
||||
});
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
static void
|
||||
collect_root_set(Context<E> &ctx,
|
||||
static void collect_root_set(Context<E> &ctx,
|
||||
tbb::concurrent_vector<InputSection<E> *> &rootset) {
|
||||
Timer t(ctx, "collect_root_set");
|
||||
|
||||
@ -141,8 +105,8 @@ collect_root_set(Context<E> &ctx,
|
||||
if (!(flags & SHF_ALLOC))
|
||||
isec->is_visited = true;
|
||||
|
||||
if (is_init_fini(*isec) || (flags & SHF_GNU_RETAIN) ||
|
||||
isec->shdr().sh_type == SHT_NOTE)
|
||||
if (is_init_fini(*isec) || is_c_identifier(isec->name()) ||
|
||||
(flags & SHF_GNU_RETAIN) || isec->shdr().sh_type == SHT_NOTE)
|
||||
enqueue_section(isec.get());
|
||||
}
|
||||
});
|
||||
@ -225,7 +189,6 @@ void gc_sections(Context<E> &ctx) {
|
||||
mark_nonalloc_fragments(ctx);
|
||||
|
||||
tbb::concurrent_vector<InputSection<E> *> rootset;
|
||||
collect_start_stop_sections(ctx, rootset);
|
||||
collect_root_set(ctx, rootset);
|
||||
mark(ctx, rootset);
|
||||
sweep(ctx);
|
||||
|
@ -1,37 +0,0 @@
|
||||
#!/bin/bash
|
||||
export LC_ALL=C
|
||||
set -e
|
||||
CC="${TEST_CC:-cc}"
|
||||
CXX="${TEST_CXX:-c++}"
|
||||
GCC="${TEST_GCC:-gcc}"
|
||||
GXX="${TEST_GXX:-g++}"
|
||||
OBJDUMP="${OBJDUMP:-objdump}"
|
||||
MACHINE="${MACHINE:-$(uname -m)}"
|
||||
testname=$(basename "$0" .sh)
|
||||
echo -n "Testing $testname ... "
|
||||
t=out/test/elf/$MACHINE/$testname
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | $CC -o $t/a.o -c -xc -
|
||||
int x1 __attribute__((section("foo_section"))) = 3;
|
||||
int x2 __attribute__((section("bar_section"))) = 5;
|
||||
EOF
|
||||
|
||||
cat <<EOF | $CC -o $t/b.o -c -xc -
|
||||
#include <stdio.h>
|
||||
|
||||
extern int __start_foo_section[];
|
||||
|
||||
int main() {
|
||||
printf("foo=%d\n", __start_foo_section[0]);
|
||||
}
|
||||
EOF
|
||||
|
||||
$CC -B. -o $t/exe $t/a.o $t/b.o -Wl,-gc-sections
|
||||
$QEMU $t/exe | grep -q 'foo=3'
|
||||
|
||||
readelf --sections $t/exe > $t/log
|
||||
grep -q foo_section $t/log
|
||||
! grep -q bar_section $t/log || false
|
||||
|
||||
echo OK
|
Loading…
Reference in New Issue
Block a user