-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move command line params to TableGen version like in the current vers…
…ion of the llvm-objdump (#177) * Move command line params to TableGen version like in the current version of the llvm-objdump * add --include-files flag * add doc/sysroot_flag.md * hide repeated help messages for joined and separate flag versions * correct include file visitor for scanning in depth
- Loading branch information
Showing
10 changed files
with
455 additions
and
257 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
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,103 @@ | ||
include "llvm/Option/OptParser.td" | ||
|
||
// Don't show this flags | ||
def HelpSkipped : OptionFlag; | ||
|
||
def help : Flag<["--"], "help">, | ||
HelpText<"Display available options (--help-hidden for more)">; | ||
def h : Flag<["-"], "h">, Alias<help>, HelpText<"Alias for --help">, Flags<[HelpHidden]>; | ||
|
||
def help_hidden : Flag<["--"], "help-hidden">, | ||
Flags<[HelpHidden]>, | ||
HelpText<"Display all available options">; | ||
|
||
def version : Flag<["--"], "version">, | ||
HelpText<"Display the version of this program">; | ||
|
||
def debug : Flag<["-"], "debug">, Flags<[HelpHidden]>; | ||
|
||
def raise : Flag<["--"], "raise">, | ||
HelpText<"Raise machine instruction">; | ||
def : Flag<["-"], "d">, Alias<raise>, HelpText<"Alias for --raise">; | ||
|
||
def include_file_EQ : Joined<["--"], "include-file=">, | ||
HelpText<"Header file with function prototypes using standard C syntax.">; | ||
def : Separate<["--"], "include-file">, Alias<include_file_EQ>, Flags<[HelpSkipped]>; | ||
def : Separate<["-"], "I">, Alias<include_file_EQ>, | ||
HelpText<"Alias for --include-file">; | ||
|
||
def include_files_EQ : Joined<["--"], "include-files=">, | ||
HelpText<"List of comma-seperated header files with function prototypes using standard C syntax.">; | ||
|
||
def filter_functions_file_EQ : Joined<["--"], "filter-functions-file=">, | ||
HelpText<"Specify which functions to raise via a configuration file.">; | ||
def : Separate<["--"], "filter-functions-file">, Alias<filter_functions_file_EQ>, Flags<[HelpSkipped]>; | ||
def : Separate<["-"], "f">, Alias<filter_functions_file_EQ>, | ||
HelpText<"Alias for --filter-functions-file">; | ||
|
||
def mcpu_EQ : Joined<["--"], "mcpu=">, | ||
MetaVarName<"cpu-name">, | ||
HelpText<"Target a specific cpu type (--mcpu=help for details)">, | ||
Flags<[HelpHidden]>; | ||
|
||
def mattr_EQ : Joined<["--"], "mattr=">, | ||
MetaVarName<"a1,+a2,-a3,...">, | ||
HelpText<"Target specific attributes (--mattr=help for details)">, | ||
Flags<[HelpHidden]>; | ||
|
||
def outfile_EQ : Joined<["--"], "outfile=">, | ||
HelpText<"Output filename">; | ||
def : Separate<["--"], "outfile">, Alias<outfile_EQ>, Flags<[HelpSkipped]>; | ||
def : Separate<["-"], "o">, Alias<outfile_EQ>, | ||
HelpText<"Alias for --outfile">; | ||
|
||
class OutputFormatOpts<string base> | ||
: KeyPathAndMacro<"OutputFormatOpts->", base, "OUTPUT_FORMAT_"> {} | ||
|
||
def output_format_EQ : Joined<["--"], "output-format=">, | ||
HelpText<"Output format: " | ||
"'ll' (emit llvm text bitcode ('.ll') file) | " | ||
"'bc' (emit llvm binary bitcode ('.bc') file) | " | ||
"'null' (emit nothing, for performance testing). " | ||
"Default is 'll'." | ||
>, | ||
Values<"ll,bc,null">, | ||
NormalizedValuesScope<"OutputFormatTy">, | ||
NormalizedValues<["LL", "BC", "Null"]>, | ||
MarshallingInfoEnum<OutputFormatOpts<"OutputFormatTy">, "LL">, | ||
Flags<[HelpHidden]>; | ||
|
||
def run_pass_EQ : Joined<["--"], "run-pass=">, | ||
MetaVarName<"pass-name">, | ||
HelpText<"Run compiler only for specified passes (comma separated list)">, | ||
Flags<[HelpHidden]>; | ||
def : Separate<["--"], "run-pass">, Alias<run_pass_EQ>, Flags<[HelpSkipped]>; | ||
|
||
def start_address_EQ : Joined<["--"], "start-address=">, | ||
MetaVarName<"address">, | ||
HelpText<"Disassemble beginning at address">, | ||
Flags<[HelpHidden]>; | ||
def : Separate<["--"], "start-address">, Alias<start_address_EQ>, Flags<[HelpSkipped]>; | ||
def stop_address_EQ : Joined<["--"], "stop-address=">, | ||
MetaVarName<"address">, | ||
HelpText<"Stop disassembly at address">, | ||
Flags<[HelpHidden]>; | ||
def : Separate<["--"], "stop-address">, Alias<stop_address_EQ>, Flags<[HelpSkipped]>; | ||
|
||
def section_EQ : Joined<["--"], "section=">, | ||
HelpText<"Operate on the specified sections only. " | ||
"With --macho dump segment,section">, | ||
Flags<[HelpHidden]>; | ||
def : Separate<["--"], "section">, Alias<section_EQ>, Flags<[HelpSkipped]>; | ||
def : Separate<["-"], "j">, Alias<section_EQ>, | ||
HelpText<"Alias for --section">, | ||
Flags<[HelpHidden]>; | ||
|
||
def sysyroot_EQ : Joined<["--"], "sysroot=">, | ||
HelpText<"Toolchain sysroot">; | ||
def : Separate<["--"], "sysroot">, Alias<sysyroot_EQ>, Flags<[HelpSkipped]>; | ||
|
||
def target_EQ : Separate<["-"], "target">, | ||
HelpText<"Target triple to disassemble for, " | ||
"see --version for available targets">, | ||
Flags<[HelpHidden]>; |
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
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,68 @@ | ||
## Using --sysroot flag | ||
|
||
--sysroot points to toolchain root. It is useful during development on a non-Linux machine to raise Linux binaries or on a Linux machine using a toolchain other than the one installed. | ||
|
||
* On linux sysroot is "/" | ||
* On MAC may show `xcrun --show-sdk-path` | ||
|
||
### Cross-building Linux x86_64 and arm binaries | ||
|
||
Instructions to build a minimal functional toolchain that may be used with `llvm-mctoll` are provided [here](https://github.com/sv99/llvm-mctoll-toolchains). These facilitate cross compilation of and raising of x86_64-linux-gnu and for arm-linux-gnueabihf targets. You may choose to create and use a toolchain of your choice. | ||
```bash | ||
# toolchain directory | ||
# ~/toolchain/arm-linux-gnueabihf | ||
# ~/toolchain/x86_64-linux-gnu | ||
# clang must be built with ARM support! | ||
|
||
# ELF 32-bit ARM Linux | ||
clang --sysroot ~/toolchain/arm-linux-gnueabihf \ | ||
-target arm-linux-gnueabihf -fuse-ld=lld \ | ||
-o hello-arm -v hello.c | ||
file helllo-arm | ||
|
||
# ELF 64-bit x86_64 Linux | ||
clang --sysroot ~/toolchain/x86_64-linux-gnu \ | ||
-target x86_64-linux-gnu -fuse-ld=lld \ | ||
-o hello-lin -v hello.c | ||
file helllo-lin | ||
``` | ||
|
||
The above has been tested to work on MacOS (and Linux). | ||
|
||
### Raising Linux binary on a non-Linux host | ||
|
||
Toolchains needs for successful parsing header file. | ||
|
||
```c | ||
# header-inc.h | ||
#include <stdio.h> | ||
``` | ||
|
||
```bash | ||
# ELF 32-bit ARM Linux | ||
llvm-mctoll --sysroot ~/toolchain/arm-linux-gnueabihf \ | ||
-target arm-linux-gnueabihf -I header-inc.h \ | ||
-debug -d hello-arm | ||
# ELF 64-bit x86_64 Linux | ||
lvm-mctoll --sysroot ~/toolchain/x86_64-linux-gnu \ | ||
-target x86_64-linux-gnu -I header-inc.h \ | ||
-debug -d hello-arm | ||
``` | ||
|
||
### Running Linux ARM binary using docker on a non-Linux development host | ||
|
||
[multiarch/qemu-user-static](https://github.com/multiarch/qemu-user-static) is to enable | ||
an execution of different multi-architecture containers | ||
|
||
```bash | ||
# prepare docker | ||
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes | ||
``` | ||
|
||
```bash | ||
# run x86_64-linux-gnu binary | ||
docker run --rm -it -v $(pwd):/work amd64/ubuntu:20.04 /work/hello-linux | ||
|
||
# run arm-linux-gnueabihf binary | ||
docker run --rm -it -v $(pwd):/work arm32v7/ubuntu:20.04 /work/hello-arm | ||
``` |
Oops, something went wrong.