mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 01:47:11 +03:00
[ELF] Fix assertion failure
This patch fixes a regression introduced in
43fa021d48
.
Fixes https://github.com/rui314/mold/issues/259
This commit is contained in:
parent
79e397ea03
commit
2f86fef3a0
@ -523,13 +523,21 @@ void scan_rels(Context<E> &ctx) {
|
||||
});
|
||||
|
||||
std::vector<Symbol<E> *> syms = flatten(vec);
|
||||
ctx.symbol_aux.reserve(syms.size());
|
||||
|
||||
auto add_aux = [&](Symbol<E> *sym) {
|
||||
if (sym->aux_idx == -1) {
|
||||
i64 sz = ctx.symbol_aux.size();
|
||||
sym->aux_idx = sz;
|
||||
ctx.symbol_aux.resize(sz + 1);
|
||||
}
|
||||
};
|
||||
|
||||
ctx.symbol_aux.resize(syms.size());
|
||||
for (i64 i = 0; i < syms.size(); i++)
|
||||
syms[i]->aux_idx = i;
|
||||
|
||||
// Assign offsets in additional tables for each dynamic symbol.
|
||||
for (Symbol<E> *sym : syms) {
|
||||
add_aux(sym);
|
||||
|
||||
if (sym->is_imported || sym->is_exported)
|
||||
ctx.dynsym->add_symbol(ctx, sym);
|
||||
|
||||
@ -583,6 +591,7 @@ void scan_rels(Context<E> &ctx) {
|
||||
// Aliases of this symbol are also copied so that they will be
|
||||
// resolved to the same address at runtime.
|
||||
for (Symbol<E> *alias : file->find_aliases(sym)) {
|
||||
add_aux(alias);
|
||||
alias->is_imported = true;
|
||||
alias->is_exported = true;
|
||||
alias->has_copyrel = true;
|
||||
|
@ -20,15 +20,14 @@ int main() {
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -o "$t"/b.o -c -x assembler -
|
||||
.globl foo, bar
|
||||
.data;
|
||||
foo:
|
||||
bar:
|
||||
.long 42
|
||||
cat <<EOF | cc -fPIC -o "$t"/b.o -c -xc -
|
||||
int foo = 42;
|
||||
extern int bar __attribute__((alias("foo")));
|
||||
extern int baz __attribute__((alias("foo")));
|
||||
EOF
|
||||
|
||||
clang -fuse-ld="$mold" -no-pie -o "$t"/exe "$t"/a.o "$t"/b.o
|
||||
clang -fuse-ld="$mold" -shared -o "$t"/c.so "$t"/b.o
|
||||
clang -fuse-ld="$mold" -no-pie -o "$t"/exe "$t"/a.o "$t"/c.so
|
||||
"$t"/exe | grep -q '42 42 1'
|
||||
|
||||
echo OK
|
||||
|
Loading…
Reference in New Issue
Block a user