Skip to content

Shared libraries are not identified by the SO name when emitting DT_NEEDED entries #50

@partaror

Description

@partaror

Shared libraries should identified by their SO name when emitting DT_NEEDED entries. Currently, if multiple different shared libraries with the same SO name are present in the link, then we emit repeated DT_NEEDED entries for the same SO name.

Reproducible example:

#!/usr/bin/env bash

cat >1.c <<\EOF
int foo() { return 1; }
EOF

cat >2.c <<\EOF
int bar() { return 3; }
EOF

LDs=(ld.eld ld.lld arm-none-eabi-ld.bfd)
SFs=(eld lld bfd)

clang -o 1.o 1.c -target arm -c -ffunction-sections
clang -o 2.o 2.c -target arm -c -ffunction-sections

for i in "${!SFs[@]}"; do
  ${LDs[$i]} -o lib1.${SFs[$i]}.so 1.o -shared -soname=foo
  ${LDs[$i]} -o lib2.${SFs[$i]}.so 2.o -shared -soname=foo
  ${LDs[$i]} -o a.${SFs[$i]}.out /dev/null lib1.${SFs[$i]}.so lib2.${SFs[$i]}.so 
done

llvm-readelf --dynamic a.eld.out | grep foo

Output:

  0x00000001 (NEEDED)   Shared library: [foo]
  0x00000001 (NEEDED)   Shared library: [foo]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions