Reputation: 6760
I have a file, foo.S, which contains ARM thumb instructions, on an Ubuntu 22.04 x86_64 machine. Is it possible to convert this into an ARM object file using as
from binutils
or do I need to create a cross-compiler toolchain? I tried
$ as -mthumb foo.S -o foo.o
However, I got
as: unrecognized option '-mthumb'
even though that's one of the options listed in man as
.
Upvotes: 1
Views: 1096
Reputation: 21513
run
sudo sh -c 'apt update;apt install binutils-arm-none-eabi;'
then the code can be compiled with
arm-none-eabi-as -mthumb foo.S -o foo.o
example:
$ echo nop > foo.S
$ arm-none-eabi-as -mthumb foo.S -o foo.o
$ echo $?
0
$ file foo.o
foo.o: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), not stripped
Upvotes: 1
Reputation: 5895
A minimal and deterministic procedure for assembling a .S file targeting the T32 instruction set on an Ubuntu 22.04 x86_64 machine could be to install the latest Arm toolchain for arm-none-eabi
if you don't have wget
installed, just execute:
sudo apt-get install wget
, or download arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi.tar.xz
using a WEB browser into you home directory.
Once done:
cd ${HOME}
# Skip the wget command hereafter if arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi.tar.xz was already downloaded into your home directory.
wget "https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi.tar.xz?rev=95edb5e17b9d43f28c74ce824f9c6f10&hash=176C4D884DBABB657ADC2AC886C8C095409547C4" -O arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi.tar.xz
tar Jxf arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi.tar.xz
You can now assemble your program using the command:
${HOME}/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc -c -mthumb foo.S -o foo.o
Please note that a file with the .S extension usually requires to be processed using cpp, the C preprocessor - this is why the command is using arm-none-eabi-gcc
, and not arm-none-eabi-as
.
Upvotes: 3