llvm-project/lld/test/elf/Mips/dynsym-table-2.test
Simon Atanasyan d449fc8671 [ELF] Add two new virtual functions to the OutputELFWriter class to control
dynamic symbol table populating and DT_NEEDED tag creation.

The `isDynSymEntryRequired` function returns true if the specified shared
library atom requires a dynamic symbol table entry. The `isNeededTagRequired`
function returns true if we need to create DT_NEEDED tag for the shared
library defined specified shared atom.

By default the both functions return true. So there is no functional changes
for all targets except MIPS. Probably we need to spread the same modifications
on other ELF targets but I want to implement and fully tested complete set of
changes for MIPS target first.

For MIPS we create a dynamic symbol table entry for a shared library atom iif
this atom is referenced by a regular defined atom. For example, if library L1
defines symbol T1, library L2 defines symbol T2 and uses symbol T1
and executable file E1 uses symbol T2 but does not use symbol T1 we create
an entry in the E1 dynamic symbol table for symbol T2 and do not create
an entry for T1.

The patch creates DT_NEEDED tags for shared libraries contain shared library
atoms which a) referenced by regular defined atoms; b) have corresponding
copy dynamic relocations (R_MIPS_COPY).

Now the patch does not take in account --as-needed / --no-as-needed command
line options. So it is too restrictive and create DT_NEEDED tags for really
needed shared libraries only. I plan to fix that by subsequent patches.

llvm-svn: 211674
2014-06-25 07:55:55 +00:00

102 lines
2.8 KiB
Plaintext

# Check that LLD does not populate a shared library dynamic symbol table
# by unnecessary symbols.
# 1. bar.so defines T2 and T3
# 2. foo.so defines T1 and references T2
# 4. foo.so dynamic table should contain T1 and T2 entries only
# RUN: yaml2obj -format=elf -docnum 1 %s > %t-bar.o
# RUN: yaml2obj -format=elf -docnum 2 %s > %t-foo.o
# RUN: lld -flavor gnu -target mipsel -shared -o %t-bar.so %t-bar.o
# RUN: lld -flavor gnu -target mipsel -shared -o %t-foo.so %t-foo.o %t-bar.so
# RUN: llvm-readobj -dt -dynamic-table %t-foo.so | FileCheck %s
# CHECK: DynamicSymbols [
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: @ (0)
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Binding: Local (0x0)
# CHECK-NEXT: Type: None (0x0)
# CHECK-NEXT: Other: 0
# CHECK-NEXT: Section: Undefined (0x0)
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: T1@ ({{.*}})
# CHECK-NEXT: Value: {{.*}}
# CHECK-NEXT: Size: 8
# CHECK-NEXT: Binding: Global (0x1)
# CHECK-NEXT: Type: Function (0x2)
# CHECK-NEXT: Other: 0
# CHECK-NEXT: Section: .text (0x4)
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: T2@ ({{.*}})
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Binding: Global (0x1)
# CHECK-NEXT: Type: Function (0x2)
# CHECK-NEXT: Other: 0
# CHECK-NEXT: Section: Undefined (0x0)
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK: 0x00000003 PLTGOT 0x1000
# CHECK-NEXT: 0x00000001 NEEDED SharedLibrary (dynsym-table-2.test.tmp-bar.so)
# CHECK-NEXT: 0x00000000 NULL 0x0
# bar.o
---
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_MIPS
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x04
Size: 0x08
Symbols:
Global:
- Name: T2
Type: STT_FUNC
Section: .text
Size: 0x04
- Name: T3
Type: STT_FUNC
Section: .text
Value: 0x04
Size: 0x04
# foo.o
---
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_MIPS
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x04
Size: 0x08
- Name: .rel.text
Type: SHT_REL
Link: .symtab
AddressAlign: 0x08
Info: .text
Relocations:
- Offset: 0
Symbol: T2
Type: R_MIPS_CALL16
Symbols:
Global:
- Name: T1
Type: STT_FUNC
Section: .text
Size: 0x08
- Name: T2
...