| # This tests the functionality of using the --wrap option. |
| # The test case is extracted by compiling and linking the following code. |
| # |
| #cat > main.c << \! |
| #int main() { |
| # foo(); |
| # return 0; |
| #} |
| #! |
| # |
| #cat > wrapfoo.c << \! |
| #int __wrap_foo() { |
| # __real_foo(); |
| # return 0; |
| #} |
| #! |
| # |
| #cat > realfoo.c << \! |
| #int foo() { |
| # return 0; |
| #} |
| #! |
| # |
| #clang main.c wrapfoo.c realfoo.c -Xlinker --wrap -Xlinker foo |
| #RUN: yaml2obj -format=elf -docnum 1 %s -o %t.main.o |
| #RUN: yaml2obj -format=elf -docnum 2 %s -o %t.wrapfoo.o |
| #RUN: yaml2obj -format=elf -docnum 3 %s -o %t.realfoo.o |
| #RUN: lld -flavor old-gnu -target x86_64 %t.main.o %t.wrapfoo.o %t.realfoo.o \ |
| #RUN: --wrap foo --wrap foo --noinhibit-exec --output-filetype=yaml -o %t2.out |
| #RUN: lld -flavor old-gnu -target x86_64 %t.main.o %t.wrapfoo.o \ |
| #RUN: --wrap foo --wrap foo --noinhibit-exec --output-filetype=yaml -o %t2.out.undef 2>&1 | \ |
| #RUN: FileCheck %s -check-prefix=CHECKUNDEF |
| #CHECKWRAP: - name: main |
| #CHECKWRAP: references: |
| #CHECKWRAP: - kind: R_X86_64_PC32 |
| #CHECKWRAP: target: __wrap_foo |
| #CHECKWRAP: - name: __wrap_foo |
| #CHECKWRAP: references: |
| #CHECKWRAP: - kind: R_X86_64_PC32 |
| #CHECKWRAP: target: foo |
| #CHECKUNDEF: Undefined symbol: {{.*}}main.o: foo |
| --- |
| FileHeader: |
| Class: ELFCLASS64 |
| Data: ELFDATA2LSB |
| OSABI: ELFOSABI_GNU |
| Type: ET_REL |
| Machine: EM_X86_64 |
| Sections: |
| - Name: .text |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC, SHF_EXECINSTR ] |
| AddressAlign: 0x0000000000000010 |
| Content: 5031C0E80000000031C05AC3 |
| - Name: .rela.text |
| Type: SHT_RELA |
| Link: .symtab |
| AddressAlign: 0x0000000000000008 |
| Info: .text |
| Relocations: |
| - Offset: 0x0000000000000004 |
| Symbol: foo |
| Type: R_X86_64_PC32 |
| Addend: -4 |
| - Name: .data |
| Type: SHT_PROGBITS |
| Flags: [ SHF_WRITE, SHF_ALLOC ] |
| AddressAlign: 0x0000000000000004 |
| Content: '' |
| - Name: .bss |
| Type: SHT_NOBITS |
| Flags: [ SHF_WRITE, SHF_ALLOC ] |
| AddressAlign: 0x0000000000000004 |
| - Name: .comment |
| Type: SHT_PROGBITS |
| Flags: [ SHF_MERGE, SHF_STRINGS ] |
| AddressAlign: 0x0000000000000001 |
| Content: 00636C616E672076657273696F6E20332E372E3020287472756E6B203232383733392920286C6C766D2F7472756E6B203232383734382900 |
| - Name: .note.GNU-stack |
| Type: SHT_PROGBITS |
| AddressAlign: 0x0000000000000001 |
| Content: '' |
| - Name: .eh_frame |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC ] |
| AddressAlign: 0x0000000000000008 |
| Content: 1400000000000000037A5200017810011B0C070890010000140000001C000000000000000C00000000410E1000000000 |
| - Name: .rela.eh_frame |
| Type: SHT_RELA |
| Link: .symtab |
| AddressAlign: 0x0000000000000008 |
| Info: .eh_frame |
| Relocations: |
| - Offset: 0x0000000000000020 |
| Symbol: .text |
| Type: R_X86_64_PC32 |
| Symbols: |
| Local: |
| - Name: .text |
| Type: STT_SECTION |
| Section: .text |
| - Name: .data |
| Type: STT_SECTION |
| Section: .data |
| - Name: .bss |
| Type: STT_SECTION |
| Section: .bss |
| - Name: .comment |
| Type: STT_SECTION |
| Section: .comment |
| - Name: .note.GNU-stack |
| Type: STT_SECTION |
| Section: .note.GNU-stack |
| - Name: .eh_frame |
| Type: STT_SECTION |
| Section: .eh_frame |
| Global: |
| - Name: main |
| Type: STT_FUNC |
| Section: .text |
| Size: 0x000000000000000C |
| - Name: foo |
| ... |
| --- |
| FileHeader: |
| Class: ELFCLASS64 |
| Data: ELFDATA2LSB |
| OSABI: ELFOSABI_GNU |
| Type: ET_REL |
| Machine: EM_X86_64 |
| Sections: |
| - Name: .text |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC, SHF_EXECINSTR ] |
| AddressAlign: 0x0000000000000010 |
| Content: 5031C0E80000000031C05AC3 |
| - Name: .rela.text |
| Type: SHT_RELA |
| Link: .symtab |
| AddressAlign: 0x0000000000000008 |
| Info: .text |
| Relocations: |
| - Offset: 0x0000000000000004 |
| Symbol: __real_foo |
| Type: R_X86_64_PC32 |
| Addend: -4 |
| - Name: .data |
| Type: SHT_PROGBITS |
| Flags: [ SHF_WRITE, SHF_ALLOC ] |
| AddressAlign: 0x0000000000000004 |
| Content: '' |
| - Name: .bss |
| Type: SHT_NOBITS |
| Flags: [ SHF_WRITE, SHF_ALLOC ] |
| AddressAlign: 0x0000000000000004 |
| - Name: .comment |
| Type: SHT_PROGBITS |
| Flags: [ SHF_MERGE, SHF_STRINGS ] |
| AddressAlign: 0x0000000000000001 |
| Content: 00636C616E672076657273696F6E20332E372E3020287472756E6B203232383733392920286C6C766D2F7472756E6B203232383734382900 |
| - Name: .note.GNU-stack |
| Type: SHT_PROGBITS |
| AddressAlign: 0x0000000000000001 |
| Content: '' |
| - Name: .eh_frame |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC ] |
| AddressAlign: 0x0000000000000008 |
| Content: 1400000000000000037A5200017810011B0C070890010000140000001C000000000000000C00000000410E1000000000 |
| - Name: .rela.eh_frame |
| Type: SHT_RELA |
| Link: .symtab |
| AddressAlign: 0x0000000000000008 |
| Info: .eh_frame |
| Relocations: |
| - Offset: 0x0000000000000020 |
| Symbol: .text |
| Type: R_X86_64_PC32 |
| Symbols: |
| Local: |
| - Name: .text |
| Type: STT_SECTION |
| Section: .text |
| - Name: .data |
| Type: STT_SECTION |
| Section: .data |
| - Name: .bss |
| Type: STT_SECTION |
| Section: .bss |
| - Name: .comment |
| Type: STT_SECTION |
| Section: .comment |
| - Name: .note.GNU-stack |
| Type: STT_SECTION |
| Section: .note.GNU-stack |
| - Name: .eh_frame |
| Type: STT_SECTION |
| Section: .eh_frame |
| Global: |
| - Name: __wrap_foo |
| Type: STT_FUNC |
| Section: .text |
| Size: 0x000000000000000C |
| - Name: __real_foo |
| ... |
| --- |
| FileHeader: |
| Class: ELFCLASS64 |
| Data: ELFDATA2LSB |
| OSABI: ELFOSABI_GNU |
| Type: ET_REL |
| Machine: EM_X86_64 |
| Sections: |
| - Name: .text |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC, SHF_EXECINSTR ] |
| AddressAlign: 0x0000000000000010 |
| Content: 31C0C3 |
| - Name: .data |
| Type: SHT_PROGBITS |
| Flags: [ SHF_WRITE, SHF_ALLOC ] |
| AddressAlign: 0x0000000000000004 |
| Content: '' |
| - Name: .bss |
| Type: SHT_NOBITS |
| Flags: [ SHF_WRITE, SHF_ALLOC ] |
| AddressAlign: 0x0000000000000004 |
| - Name: .comment |
| Type: SHT_PROGBITS |
| Flags: [ SHF_MERGE, SHF_STRINGS ] |
| AddressAlign: 0x0000000000000001 |
| Content: 00636C616E672076657273696F6E20332E372E3020287472756E6B203232383733392920286C6C766D2F7472756E6B203232383734382900 |
| - Name: .note.GNU-stack |
| Type: SHT_PROGBITS |
| AddressAlign: 0x0000000000000001 |
| Content: '' |
| - Name: .eh_frame |
| Type: SHT_PROGBITS |
| Flags: [ SHF_ALLOC ] |
| AddressAlign: 0x0000000000000008 |
| Content: 1400000000000000037A5200017810011B0C070890010000140000001C00000000000000030000000000000000000000 |
| - Name: .rela.eh_frame |
| Type: SHT_RELA |
| Link: .symtab |
| AddressAlign: 0x0000000000000008 |
| Info: .eh_frame |
| Relocations: |
| - Offset: 0x0000000000000020 |
| Symbol: .text |
| Type: R_X86_64_PC32 |
| Symbols: |
| Local: |
| - Name: .text |
| Type: STT_SECTION |
| Section: .text |
| - Name: .data |
| Type: STT_SECTION |
| Section: .data |
| - Name: .bss |
| Type: STT_SECTION |
| Section: .bss |
| - Name: .comment |
| Type: STT_SECTION |
| Section: .comment |
| - Name: .note.GNU-stack |
| Type: STT_SECTION |
| Section: .note.GNU-stack |
| - Name: .eh_frame |
| Type: STT_SECTION |
| Section: .eh_frame |
| Global: |
| - Name: foo |
| Type: STT_FUNC |
| Section: .text |
| Size: 0x0000000000000003 |
| ... |