Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LLVM][llvm-objcopy] Added basic plumbing to get things started
As discussed on llvm-dev I've implemented the first basic steps towards llvm-objcopy/llvm-objtool (name pending). This change adds the ability to copy (without modification) 64-bit little endian ELF executables that have SHT_PROGBITS, SHT_NOBITS, SHT_NULL and SHT_STRTAB sections. Patch by Jake Ehrlich Differential Revision: https://reviews.llvm.org/D33964 llvm-svn: 308559
- Loading branch information
Showing
11 changed files
with
811 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy %t %t2 | ||
# RUN: llvm-readobj -sections %t2 | FileCheck %s | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .bss | ||
Type: SHT_NOBITS | ||
Flags: [ SHF_ALLOC ] | ||
AddressAlign: 0x0000000000000010 | ||
Size: 64 | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ] | ||
AddressAlign: 0x0000000000000010 | ||
Content: "00000000" | ||
|
||
# CHECK: Type: SHT_NULL | ||
|
||
# CHECK: Name: .shstrtab | ||
# CHECK-NEXT: Type: SHT_STRTAB | ||
# CHECK-NEXT: Flags [ | ||
# CHECK-NEXT: ] | ||
|
||
# CHECK: Name: .bss | ||
# CHECK-NEXT: Type: SHT_NOBITS | ||
# CHECK-NEXT: Flags [ | ||
# CHECK-NEXT: SHF_ALLOC | ||
# CHECK-NEXT: ] | ||
# CHECK-NEXT: Address: | ||
# CHECK-NEXT: Offset: [[OFFSET:0x[0-9A-F]+]] | ||
# CHECK-NEXT: Size: 64 | ||
|
||
# CHECK: Name: .text | ||
# CHECK-NEXT: Type: SHT_PROGBITS | ||
# CHECK-NEXT: Flags [ | ||
# CHECK-NEXT: SHF_ALLOC | ||
# CHECK-NEXT: SHF_EXECINSTR | ||
# CHECK-NEXT: ] | ||
# CHECK-NEXT: Address: | ||
# CHECK-NEXT: Offset: [[OFFSET]] | ||
# CHECK-NEXT: Size: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# RUN: yaml2obj %s > %t | ||
# RUN: llvm-objcopy %t %t2 | ||
# RUN: llvm-readobj -sections %t2 | FileCheck %s | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ] | ||
Address: 0x0 | ||
AddressAlign: 0x0000000000001000 | ||
Content: "00000000" | ||
- Name: .empty | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC ] | ||
Address: 0x1000 | ||
AddressAlign: 0x0000000000001000 | ||
Content: "" | ||
- Name: .data | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC ] | ||
Address: 0x1000 | ||
AddressAlign: 0x0000000000001000 | ||
Content: "00000000" | ||
|
||
|
||
# CHECK: Name: .text | ||
# CHECK-NEXT: Type: SHT_PROGBITS | ||
# CHECK-NEXT: Flags [ | ||
# CHECK-NEXT: SHF_ALLOC | ||
# CHECK-NEXT: SHF_EXECINSTR | ||
# CHECK-NEXT: ] | ||
|
||
# CHECK: Name: .empty | ||
# CHECK-NEXT: Type: SHT_PROGBITS | ||
# CHECK-NEXT: Flags [ | ||
# CHECK-NEXT: SHF_ALLOC | ||
# CHECK-NEXT: ] | ||
# CHECK-NEXT: Address: 0x1000 | ||
# CHECK-NEXT: Offset: 0x2000 | ||
# CHECK-NEXT: Size: 0 | ||
|
||
# CHECK: Name: .data | ||
# CHECK-NEXT: Type: SHT_PROGBITS | ||
# CHECK-NEXT: Flags [ | ||
# CHECK-NEXT: SHF_ALLOC | ||
# CHECK-NEXT: ] | ||
# CHECK-NEXT: Address: 0x1000 | ||
# CHECK-NEXT: Offset: 0x2000 | ||
# CHECK-NEXT: Size: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# RUN: yaml2obj %s -o %t | ||
# RUN: llvm-objcopy %t %t2 | ||
# RUN: llvm-readobj -program-headers %t2 | FileCheck %s | ||
|
||
!ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ] | ||
AddressAlign: 0x0000000000001000 | ||
Content: "00000000" | ||
- Name: .init | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ] | ||
Content: "00000000" | ||
AddressAlign: 0x0000000000000010 | ||
- Name: .data | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC ] | ||
Content: "00000000" | ||
AddressAlign: 0x0000000000001000 | ||
ProgramHeaders: | ||
- Type: PT_LOAD | ||
Flags: [ PF_X, PF_R ] | ||
VAddr: 0xAAAA1000 | ||
PAddr: 0xFFFF1000 | ||
Sections: | ||
- Section: .text | ||
- Section: .init | ||
- Type: PT_LOAD | ||
Flags: [ PF_R ] | ||
VAddr: 0xAAAA2000 | ||
PAddr: 0xFFFF2000 | ||
Sections: | ||
- Section: .data | ||
|
||
#CHECK: ProgramHeaders [ | ||
#CHECK-NEXT: ProgramHeader { | ||
#CHECK-NEXT: Type: PT_LOAD | ||
#CHECK-NEXT: Offset: 0x1000 | ||
#CHECK-NEXT: VirtualAddress: 0xAAAA1000 | ||
#CHECK-NEXT: PhysicalAddress: 0xFFFF1000 | ||
#CHECK-NEXT: FileSize: 20 | ||
#CHECK-NEXT: MemSize: 20 | ||
#CHECK-NEXT: Flags [ | ||
#CHECK-NEXT: PF_R | ||
#CHECK-NEXT: PF_X | ||
#CHECK-NEXT: ] | ||
#CHECK-NEXT: Alignment: 4096 | ||
#CHECK-NEXT: } | ||
#CHECK-NEXT: ProgramHeader { | ||
#CHECK-NEXT: Type: PT_LOAD | ||
#CHECK-NEXT: Offset: 0x2000 | ||
#CHECK-NEXT: VirtualAddress: 0xAAAA2000 | ||
#CHECK-NEXT: PhysicalAddress: 0xFFFF2000 | ||
#CHECK-NEXT: FileSize: 4 | ||
#CHECK-NEXT: MemSize: 4 | ||
#CHECK-NEXT: Flags [ | ||
#CHECK-NEXT: PF_R | ||
#CHECK-NEXT: ] | ||
#CHECK-NEXT: Alignment: 4096 | ||
#CHECK-NEXT: } | ||
#CHECK-NEXT:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
set(LLVM_LINK_COMPONENTS | ||
Core | ||
Object | ||
Support | ||
) | ||
add_llvm_tool(llvm-objcopy | ||
llvm-objcopy.cpp | ||
Object.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
;===- ./tools/llvm-objcopy/LLVMBuild.txt -----------------------*- Conf -*--===; | ||
; | ||
; The LLVM Compiler Infrastructure | ||
; | ||
; This file is distributed under the University of Illinois Open Source | ||
; License. See LICENSE.TXT for details. | ||
; | ||
;===------------------------------------------------------------------------===; | ||
; | ||
; This is an LLVMBuild description file for the components in this subdirectory. | ||
; | ||
; For more information on the LLVMBuild system, please see: | ||
; | ||
; http://llvm.org/docs/LLVMBuild.html | ||
; | ||
;===------------------------------------------------------------------------===; | ||
[component_0] | ||
type = Tool | ||
name = llvm-objcopy | ||
parent = Tools | ||
required_libraries = Object |
Oops, something went wrong.