mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-02-11 13:02:10 +08:00
This commit adds disassembler styling for the ARM architecture. The ARM disassembler is driven by several instruction tables, e.g. cde_opcodes, coprocessor_opcodes, neon_opcodes, etc The type for elements in each table can vary, but they all have one thing in common, a 'const char *assembler' field. This field contains a string that describes the assembler syntax of the instruction. Embedded within that assembler syntax are various escape characters, prefixed with a '%'. Here's an example of a very simple instruction from the arm_opcodes table: "pld\t%a" The '%a' indicates a particular type of operand, the function print_insn_arm processes the arm_opcodes table, and includes a switch statement that handles the '%a' operand, and takes care of printing the correct value for that instruction operand. It is worth noting that there are many print_* functions, each function handles a single *_opcodes table, and includes its own switch statement for operand handling. As a result, every *_opcodes table uses a different mapping for the operand escape sequences. This means that '%a' might print an address for one *_opcodes table, but in a different *_opcodes table '%a' might print a register operand. Notice as well that in our example above, the instruction mnemonic 'pld' is embedded within the assembler string. Some instructions also include comments within the assembler string, for example, also from the arm_opcodes table: "nop\t\t\t@ (mov r0, r0)" here, everything after the '@' is a comment that is displayed at the end of the instruction disassembly. The next complexity is that the meaning of some escape sequences is not necessarily fixed. Consider these two examples from arm_opcodes: "ldrex%c\tr%12-15d, [%16-19R]" "setpan\t#%9-9d" Here, the '%d' escape is used with a bitfield modifier, '%12-15d' in the first instruction, and '%9-9d' in the second instruction, but, both of these are the '%d' escape. However, in the first instruction, the '%d' is used to print a register number, notice the 'r' immediately before the '%d'. In the second instruction the '%d' is used to print an immediate, notice the '#' just before the '%d'. We have two problems here, first, the '%d' needs to know if it should use register style or immediate style, and secondly, the 'r' and '#' characters also need to be styled appropriately. The final thing we must consider is that some escape codes result in more than just a single operand being printed, for example, the '%q' operand as used in arm_opcodes ends up calling arm_decode_shift, which can print a register name, a shift type, and a shift amount, this could end up using register, sub-mnemonic, and immediate styles, as well as the text style for things like ',' between the different parts. I propose a three layer approach to adding styling: (1) Basic state machine: When we start printing an instruction we should maintain the idea of a 'base_style'. Every character from the assembler string will be printed using the base_style. The base_style will start as mnemonic, as each instruction starts with an instruction mnemonic. When we encounter the first '\t' character, the base_style will change to text. When we encounter the first '@' the base_style will change to comment_start. This simple state machine ensures that for simple instructions the basic parts, except for the operands themselves, will be printed in the correct style. (2) Simple operand styling: For operands that only have a single meaning, or which expand to multiple parts, all of which have a consistent meaning, then I will simply update the operand printing code to print the operand with the correct style. This will cover a large number of the operands, and is the most consistent with how styling has been added to previous architectures. (3) New styling syntax in assembler strings: For cases like the '%d' that I describe above, I propose adding a new extension to the assembler syntax. This extension will allow me to temporarily change the base_style. Operands like '%d', will then print using the base_style rather than using a fixed style. Here are the two examples from above that use '%d', updated with the new syntax extension: "ldrex%c\t%{R:r%12-15d%}, [%16-19R]" "setpan\t%{I:#%9-9d%}" The syntax has the general form '%{X:....%}' where the 'X' character changes to indicate a different style. In the first instruction I use '%{R:...%}' to change base_style to the register style, and in the second '%{I:...%}' changes base_style to immediate style. Notice that the 'r' and '#' characters are included within the new style group, this ensures that these characters are printed with the correct style rather than as text. The function decode_base_style maps from character to style. I've included a character for each style for completeness, though only a small number of styles are currently used. I have updated arm-dis.c to the above scheme, and checked all of the tests in gas/testsuite/gas/arm/, and the styling looks reasonable. There are no regressions on the ARM gas/binutils/ld tests that I can see, so I don't believe I've changed the output layout at all. There were two binutils tests for which I needed to force the disassembler styling off. I can't guarantee that I've not missed some untested corners of the disassembler, or that I might have just missed some incorrectly styled output when reviewing the test results, but I don't believe I've introduced any changes that could break the disassembler - the worst should be some aspect is not styled correctly. |
||
---|---|---|
.. | ||
doc | ||
po | ||
testsuite | ||
.gitignore | ||
aclocal.m4 | ||
addr2line.c | ||
ar.c | ||
arlex.l | ||
arparse.y | ||
arsup.c | ||
arsup.h | ||
bfdtest1.c | ||
bfdtest2.c | ||
bin2c.c | ||
binemul.c | ||
binemul.h | ||
BRANCHES | ||
bucomm.c | ||
bucomm.h | ||
budbg.h | ||
ChangeLog | ||
ChangeLog-0001 | ||
ChangeLog-0203 | ||
ChangeLog-2004 | ||
ChangeLog-2005 | ||
ChangeLog-2006 | ||
ChangeLog-2007 | ||
ChangeLog-2008 | ||
ChangeLog-2009 | ||
ChangeLog-2010 | ||
ChangeLog-2011 | ||
ChangeLog-2012 | ||
ChangeLog-2013 | ||
ChangeLog-2014 | ||
ChangeLog-2015 | ||
ChangeLog-2016 | ||
ChangeLog-2017 | ||
ChangeLog-2018 | ||
ChangeLog-2019 | ||
ChangeLog-2020 | ||
ChangeLog-9197 | ||
ChangeLog-9899 | ||
coffdump.c | ||
coffgrok.c | ||
coffgrok.h | ||
config.in | ||
configure | ||
configure.ac | ||
configure.com | ||
configure.tgt | ||
cxxfilt.c | ||
debug.c | ||
debug.h | ||
deflex.l | ||
defparse.y | ||
demanguse.c | ||
demanguse.h | ||
dep-in.sed | ||
dlltool.c | ||
dlltool.h | ||
dllwrap.c | ||
dwarf-mode.el | ||
dwarf.c | ||
dwarf.h | ||
elfcomm.c | ||
elfcomm.h | ||
elfedit.c | ||
embedspu.sh | ||
emul_aix.c | ||
emul_vanilla.c | ||
filemode.c | ||
is-ranlib.c | ||
is-strip.c | ||
MAINTAINERS | ||
Makefile.am | ||
Makefile.in | ||
makefile.vms | ||
maybe-ranlib.c | ||
maybe-strip.c | ||
mclex.c | ||
mcparse.y | ||
NEWS | ||
nm.c | ||
not-ranlib.c | ||
not-strip.c | ||
objcopy.c | ||
objdump.c | ||
objdump.h | ||
od-elf32_avr.c | ||
od-macho.c | ||
od-xcoff.c | ||
prdbg.c | ||
ranlib.sh | ||
rclex.c | ||
rcparse.y | ||
rdcoff.c | ||
rddbg.c | ||
readelf.c | ||
README | ||
README-how-to-make-a-release | ||
rename.c | ||
resbin.c | ||
rescoff.c | ||
resrc.c | ||
resres.c | ||
sanity.sh | ||
size.c | ||
srconv.c | ||
stabs.c | ||
strings.c | ||
sysdep.h | ||
sysdump.c | ||
sysinfo.y | ||
syslex_wrap.c | ||
syslex.l | ||
sysroff.info | ||
unwind-ia64.c | ||
unwind-ia64.h | ||
version.c | ||
windint.h | ||
windmc.c | ||
windmc.h | ||
windres.c | ||
windres.h | ||
winduni.c | ||
winduni.h | ||
wrstabs.c |
README for BINUTILS
These are the GNU binutils. These are utilities of use when dealing
with binary files, either object files or executables. These tools
consist of the linker (ld), the assembler (gas), and the profiler
(gprof) each of which have their own sub-directory named after them.
There is also a collection of other binary tools, including the
disassembler (objdump) in this directory. These tools make use of a
pair of libraries (bfd and opcodes) and a common set of header files
(include).
There are README and NEWS files in most of the program sub-directories
which give more information about those specific programs.
Copyright Notices
=================
Copyright years on binutils source files may be listed using range
notation, e.g., 1991-2021, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.
Unpacking and Installation -- quick overview
============================================
When you unpack the binutils archive file, you will get a directory
called something like `binutils-XXX', where XXX is the number of the
release. (Probably 2.36 or higher). This directory contains
various files and sub-directories. Most of the files in the top
directory are for information and for configuration. The actual
source code is in sub-directories.
To build binutils you will need a C99 compliant compiler and library.
You can just do:
cd binutils-XXX
./configure [options]
make
make install # copies the programs files into /usr/local/bin
# by default.
This will configure and build all the libraries as well as the
assembler, the binutils, and the linker.
If you have GNU make, we recommend building in a different directory:
mkdir objdir
cd objdir
../binutils-XXX/configure [options]
make
make install
This relies on the VPATH feature of GNU make.
By default, the binutils will be configured to support the system on
which they are built. When doing cross development, use the --target
configure option to specify a different target, eg:
./configure --target=powerpc64le-linux
The --enable-targets option adds support for more binary file formats
besides the default. List them as the argument to --enable-targets,
separated by commas. For example:
./configure --enable-targets=powerpc-linux,rs6000-aix
The name 'all' compiles in support for all valid BFD targets:
./configure --enable-targets=all
On 32-bit hosts though, this support will be restricted to 32-bit
target unless the --enable-64-bit-bfd option is also used:
./configure --enable-64-bit-bfd --enable-targets=all
You can also specify the --enable-shared option when you run
configure. This will build the BFD and opcodes libraries as shared
libraries. You can use arguments with the --enable-shared option to
indicate that only certain libraries should be built shared; for
example, --enable-shared=bfd. The only potential shared libraries in
a binutils release are bfd and opcodes.
The binutils will be linked against the shared libraries. The build
step will attempt to place the correct library in the run-time search
path for the binaries. However, in some cases, after you install the
binaries, you may have to set an environment variable, normally
LD_LIBRARY_PATH, so that the system can find the installed libbfd
shared library.
On hosts that support shared system libraries the binutils will be
linked against them. If you have static versions of the system
libraries installed as well and you wish to create static binaries
instead then use the LDFLAGS environment variable, like this:
../binutils-XXX/configure LDFLAGS="--static" [more options]
Note: the two dashes are important. The binutils make use of the
libtool script which has a special interpretation of "-static" when it
is in the LDFLAGS environment variable.
To build under openVMS/AXP, see the file makefile.vms in the top level
directory.
Native Language Support
=======================
By default Native Language Support will be enabled for binutils. On
some systems however this support is not present and can lead to error
messages such as "undefined reference to `libintl_gettext'" when
building there tools. If that happens the NLS support can be disabled
by adding the --disable-nls switch to the configure line like this:
../binutils-XXX/configure --disable-nls
If you don't have ar
====================
If your system does not already have an 'ar' program, the normal
binutils build process will not work. In this case, run configure as
usual. Before running make, run this script:
#!/bin/sh
MAKE_PROG="${MAKE-make}"
MAKE="${MAKE_PROG} AR=true LINK=true"
export MAKE
${MAKE} $* all-libiberty
${MAKE} $* all-intl
${MAKE} $* all-bfd
cd binutils
MAKE="${MAKE_PROG}"
export MAKE
${MAKE} $* ar_DEPENDENCIES= ar_LDADD='../bfd/*.o ../libiberty/*.o `if test -f ../intl/gettext.o; then echo '../intl/*.o'; fi`' ar
This script will build an ar program in binutils/ar. Move binutils/ar
into a directory on your PATH. After doing this, you can run make as
usual to build the complete binutils distribution. You do not need
the ranlib program in order to build the distribution.
Porting
=======
Binutils-2.36 supports many different architectures, but there
are many more not supported, including some that were supported
by earlier versions. We are hoping for volunteers to improve this
situation.
The major effort in porting binutils to a new host and/or target
architecture involves the BFD library. There is some documentation
in ../bfd/doc. The file ../gdb/doc/gdbint.texinfo (distributed
with gdb-5.x) may also be of help.
Reporting bugs
==============
Please report bugs via
https://sourceware.org/bugzilla/enter_bug.cgi?product=binutils
Please include the following in bug reports:
- A description of exactly what went wrong, and exactly what should have
happened instead.
- The configuration name(s) given to the "configure" script. The
"config.status" file should have this information. This is assuming
you built binutils yourself. If you didn't build binutils youself,
then we need information regarding your machine and operating system,
and it may be more appropriate to report bugs to wherever you obtained
binutils.
- The options given to the tool (gas, objcopy, ld etc.) at run time.
- The actual input file that caused the problem.
Always mention the version number you are running; this is printed by
running any of the binutils with the --version option. We appreciate
reports about bugs, but we do not promise to fix them, particularly so
when the bug report is against an old version. If you are able, please
consider building the latest tools from git to check that your bug has
not already been fixed.
When reporting problems about gas and ld, it's useful to provide a
testcase that triggers the problem. In the case of a gas problem, we
want input files to gas and command line switches used. The inputs to
gas are _NOT_ .c or .i files, but rather .s files. If your original
source was a C program, you can generate the .s file and see the command
line options by passing -v -save-temps to gcc in addition to all the
usual options you use. The reason we don't want C files is that we
might not have a C compiler around for the target you use. While it
might be possible to build a compiler, that takes considerable time and
disk space, and we might not end up with exactly the same compiler you
use.
In the case of a ld problem, the input files are .o, .a and .so files,
and possibly a linker script specified with -T. Again, when using gcc
to link, you can see these files by adding options to the gcc command
line. Use -v -save-temps -Wl,-t, except that on targets that use gcc's
collect2, you would add -v -save-temps -Wl,-t,-debug. The -t option
tells ld to print all files and libraries used, so that, for example,
you can associate -lc on the ld command line with the actual libc used.
Note that your simple two line C program to trigger a problem typically
expands into several megabytes of objects by the time you include
libraries.
There is a limit to the size of attachments accepted by bugzilla. If
compressing your testcase does not result in an acceptable size tar or
zip file, please put large testcases somewhere on an ftp or web site.
Better still, try to reduce the testcase, for example, try to develop
a ld testcase that doesn't use system libraries. However, please be
sure it is a complete testcase and that it really does demonstrate the
problem. Also, don't bother paring it down if that will cause large
delays in filing the bug report.
If you expect to be contributing a large number of test cases, it would
be helpful if you would look at the test suite included in the release
(based on the Deja Gnu testing framework, available from the usual ftp
sites) and write test cases to fit into that framework. This is
certainly not required.
VMS
===
This section was written by Klaus K"ampf <kkaempf@rmi.de>. It
describes how to build and install the binutils on openVMS (Alpha and
Vax). (The BFD library only supports reading Vax object files.)
Compiling the release:
To compile the gnu binary utilities and the gnu assembler, you'll
need DEC C or GNU C for openVMS/Alpha. You'll need *both* compilers
on openVMS/Vax.
Compiling with either DEC C or GNU C works on openVMS/Alpha only. Some
of the opcodes and binutils files trap a bug in the DEC C optimizer,
so these files must be compiled with /noopt.
Compiling on openVMS/Vax is a bit complicated, as the bfd library traps
a bug in GNU C and the gnu assembler a bug in (my version of) DEC C.
I never tried compiling with VAX C.
You further need GNU Make Version 3.76 or later. This is available
at ftp.progis.de or any GNU archive site. The makefiles assume that
gmake starts gnu make as a foreign command.
If you're compiling with DEC C or VAX C, you must run
$ @setup
before starting gnu-make. This isn't needed with GNU C.
On the Alpha you can choose the compiler by editing the toplevel
makefile.vms. Either select CC=cc (for DEC C) or CC=gcc (for GNU C)
Installing the release
Provided that your directory setup conforms to the GNU on openVMS
standard, you already have a concealed device named 'GNU_ROOT'.
In this case, a simple
$ gmake install
suffices to copy all programs and libraries to the proper directories.
Define the programs as foreign commands by adding these lines to your
login.com:
$ gas :== $GNU_ROOT:[bin]as.exe
$ size :== $GNU_ROOT:[bin]size.exe
$ nm :== $GNU_ROOT:[bin]nm.exe
$ objdump :== $GNU_ROOT:[bin]objdump.exe
$ strings :== $GNU_ROOT:[bin]strings.exe
If you have a different directory setup, copy the binary utilities
([.binutils]size.exe, [.binutils]nm.exe, [.binutils]objdump.exe,
and [.binutils]strings.exe) and the gnu assembler and preprocessor
([.gas]as.exe and [.gas]gasp.exe]) to a directory of your choice
and define all programs as foreign commands.
If you're satisfied with the compilation, you may want to remove
unneeded objects and libraries:
$ gmake clean
If you have any problems or questions about the binutils on VMS, feel
free to mail me at kkaempf@rmi.de.
Copyright (C) 2012-2022 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.