Skip to content

Commit

Permalink
Merging r352606:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
r352606 | dim | 2019-01-30 07:31:52 +0100 (Wed, 30 Jan 2019) | 27 lines

Recognize FreeBSD specific BFD names in OUTPUT_FORMAT

Summary:
After rLLD344952 ("Add OUTPUT_FORMAT linker script directive support"),
using BFD names such as `elf64-x86-64-freebsd` the `OUTPUT_FORMAT`
linker script command does not work anymore, resulting in errors like:

```
ld: error: /home/dim/src/clang800-import/stand/efi/loader/arch/amd64/ldscript.amd64:2: unknown output format name: elf64-x86-64-freebsd
>>> OUTPUT_FORMAT("elf64-x86-64-freebsd", "elf64-x86-64-freebsd", "elf64-x86-64-freebsd")
>>>               ^
```

To fix this, recognize a `-freebsd` suffix in BFD names, and also set
`Configuration::OSABI` to `ELFOSABI_FREEBSD` for those cases.

Add and/or update several test cases to check for the correct results of
these new `OUTPUT_FORMAT` arguments.

Reviewers: ruiu, atanasyan, grimar, hokein, emaste, espindola

Reviewed By: ruiu

Subscribers: nemanjai, javed.absar, arichardson, krytarowski, kristof.beyls, kbarton, llvm-commits

Differential Revision: https://reviews.llvm.org/D57283

------------------------------------------------------------------------

llvm-svn: 352853
  • Loading branch information
zmodem committed Feb 1, 2019
1 parent 15decd1 commit 538ee73
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lld/ELF/ScriptParser.cpp
Expand Up @@ -390,6 +390,7 @@ static std::pair<ELFKind, uint16_t> parseBfdName(StringRef S) {
.Case("elf32-iamcu", {ELF32LEKind, EM_IAMCU})
.Case("elf32-littlearm", {ELF32LEKind, EM_ARM})
.Case("elf32-x86-64", {ELF32LEKind, EM_X86_64})
.Case("elf64-aarch64", {ELF64LEKind, EM_AARCH64})
.Case("elf64-littleaarch64", {ELF64LEKind, EM_AARCH64})
.Case("elf64-powerpc", {ELF64BEKind, EM_PPC64})
.Case("elf64-powerpcle", {ELF64LEKind, EM_PPC64})
Expand All @@ -408,11 +409,14 @@ static std::pair<ELFKind, uint16_t> parseBfdName(StringRef S) {
void ScriptParser::readOutputFormat() {
expect("(");

StringRef S = unquote(next());
StringRef Name = unquote(next());
StringRef S = Name;
if (S.consume_back("-freebsd"))
Config->OSABI = ELFOSABI_FREEBSD;

std::tie(Config->EKind, Config->EMachine) = parseBfdName(S);
if (Config->EMachine == EM_NONE)
setError("unknown output format name: " + S);
setError("unknown output format name: " + Name);
if (S == "elf32-ntradlittlemips" || S == "elf32-ntradbigmips")
Config->MipsN32Abi = true;

Expand Down
23 changes: 23 additions & 0 deletions lld/test/ELF/emulation-aarch64.s
Expand Up @@ -30,5 +30,28 @@
# AARCH64-NEXT: Flags [ (0x0)
# AARCH64-NEXT: ]

# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %taarch64fbsd
# RUN: echo 'OUTPUT_FORMAT(elf64-aarch64-freebsd)' > %taarch64fbsd.script
# RUN: ld.lld %taarch64fbsd.script %taarch64fbsd -o %t2aarch64fbsd
# RUN: llvm-readobj -file-headers %t2aarch64fbsd | FileCheck --check-prefix=AARCH64-FBSD %s
# AARCH64-FBSD: ElfHeader {
# AARCH64-FBSD-NEXT: Ident {
# AARCH64-FBSD-NEXT: Magic: (7F 45 4C 46)
# AARCH64-FBSD-NEXT: Class: 64-bit (0x2)
# AARCH64-FBSD-NEXT: DataEncoding: LittleEndian (0x1)
# AARCH64-FBSD-NEXT: FileVersion: 1
# AARCH64-FBSD-NEXT: OS/ABI: FreeBSD (0x9)
# AARCH64-FBSD-NEXT: ABIVersion: 0
# AARCH64-FBSD-NEXT: Unused: (00 00 00 00 00 00 00)
# AARCH64-FBSD-NEXT: }
# AARCH64-FBSD-NEXT: Type: Executable (0x2)
# AARCH64-FBSD-NEXT: Machine: EM_AARCH64 (0xB7)
# AARCH64-FBSD-NEXT: Version: 1
# AARCH64-FBSD-NEXT: Entry:
# AARCH64-FBSD-NEXT: ProgramHeaderOffset: 0x40
# AARCH64-FBSD-NEXT: SectionHeaderOffset:
# AARCH64-FBSD-NEXT: Flags [ (0x0)
# AARCH64-FBSD-NEXT: ]

.globl _start
_start:
32 changes: 32 additions & 0 deletions lld/test/ELF/emulation-ppc.s
Expand Up @@ -35,6 +35,38 @@
# PPC64-NEXT: StringTableSectionIndex:
# PPC64-NEXT: }

# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-freebsd %s -o %tppc64fbsd
# RUN: echo 'OUTPUT_FORMAT(elf64-powerpc-freebsd)' > %tppc64fbsd.script
# RUN: ld.lld %tppc64fbsd.script %tppc64fbsd -o %t2ppc64fbsd
# RUN: llvm-readobj -file-headers %t2ppc64fbsd | FileCheck --check-prefix=PPC64-FBSD %s

# PPC64-FBSD: ElfHeader {
# PPC64-FBSD-NEXT: Ident {
# PPC64-FBSD-NEXT: Magic: (7F 45 4C 46)
# PPC64-FBSD-NEXT: Class: 64-bit (0x2)
# PPC64-FBSD-NEXT: DataEncoding: BigEndian (0x2)
# PPC64-FBSD-NEXT: FileVersion: 1
# PPC64-FBSD-NEXT: OS/ABI: FreeBSD (0x9)
# PPC64-FBSD-NEXT: ABIVersion: 0
# PPC64-FBSD-NEXT: Unused: (00 00 00 00 00 00 00)
# PPC64-FBSD-NEXT: }
# PPC64-FBSD-NEXT: Type: Executable (0x2)
# PPC64-FBSD-NEXT: Machine: EM_PPC64 (0x15)
# PPC64-FBSD-NEXT: Version: 1
# PPC64-FBSD-NEXT: Entry:
# PPC64-FBSD-NEXT: ProgramHeaderOffset: 0x40
# PPC64-FBSD-NEXT: SectionHeaderOffset:
# PPC64-FBSD-NEXT: Flags [ (0x2)
# PPC64-FBSD-NEXT: 0x2
# PPC64-FBSD-NEXT: ]
# PPC64-FBSD-NEXT: HeaderSize: 64
# PPC64-FBSD-NEXT: ProgramHeaderEntrySize: 56
# PPC64-FBSD-NEXT: ProgramHeaderCount:
# PPC64-FBSD-NEXT: SectionHeaderEntrySize: 64
# PPC64-FBSD-NEXT: SectionHeaderCount:
# PPC64-FBSD-NEXT: StringTableSectionIndex:
# PPC64-FBSD-NEXT: }

# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %tppc64le
# RUN: ld.lld -m elf64lppc %tppc64le -o %t2ppc64le
# RUN: llvm-readobj -file-headers %t2ppc64le | FileCheck --check-prefix=PPC64LE %s
Expand Down
10 changes: 8 additions & 2 deletions lld/test/ELF/emulation-x86.s
Expand Up @@ -7,6 +7,9 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.sysv
# RUN: ld.lld -m elf_amd64_fbsd %t.sysv -o %t.freebsd
# RUN: llvm-readobj -file-headers %t.freebsd | FileCheck --check-prefix=AMD64 %s
# RUN: echo 'OUTPUT_FORMAT(elf64-x86-64-freebsd)' > %t4x64.script
# RUN: ld.lld %t4x64.script %tx64 -o %t4x64
# RUN: llvm-readobj -file-headers %t4x64 | FileCheck --check-prefix=AMD64 %s
# AMD64: ElfHeader {
# AMD64-NEXT: Ident {
# AMD64-NEXT: Magic: (7F 45 4C 46)
Expand Down Expand Up @@ -137,10 +140,13 @@
# X86-NEXT: }

# RUN: llvm-mc -filetype=obj -triple=i686-unknown-freebsd %s -o %tx86fbsd
# RUN: ld.lld -m elf_i386_fbsd %tx86fbsd -o %t2x86_fbsd
# RUN: llvm-readobj -file-headers %t2x86_fbsd | FileCheck --check-prefix=X86FBSD %s
# RUN: ld.lld -m elf_i386_fbsd %tx86fbsd -o %t2x86fbsd
# RUN: llvm-readobj -file-headers %t2x86fbsd | FileCheck --check-prefix=X86FBSD %s
# RUN: ld.lld %tx86fbsd -o %t3x86fbsd
# RUN: llvm-readobj -file-headers %t3x86fbsd | FileCheck --check-prefix=X86FBSD %s
# RUN: echo 'OUTPUT_FORMAT(elf32-i386-freebsd)' > %t4x86fbsd.script
# RUN: ld.lld %t4x86fbsd.script %tx86fbsd -o %t4x86fbsd
# RUN: llvm-readobj -file-headers %t4x86fbsd | FileCheck --check-prefix=X86FBSD %s
# X86FBSD: ElfHeader {
# X86FBSD-NEXT: Ident {
# X86FBSD-NEXT: Magic: (7F 45 4C 46)
Expand Down

0 comments on commit 538ee73

Please sign in to comment.