An introduction to GCC and GCC’s plugins

1. Brief introduction to GNU’s GCC The GNU toolchain is a collection of tools and libraries produced in the context of the GNU project. In 1983, Richard Stallman announced the GNU project. Its goal was to give the community freedom and control in their use of computing devices by developing (collaboratively) free software and letting users modify, copy, and distribute it freely. The GNU toolchain was part of that software and today includes some of the most widespread tools used to develop and compile application such as: GNU make:…

How to run a program with commandline arguments using GDB within a Bash script?

Run gdb with --args parameter: gdb --args executablename arg1 arg2 arg3 If you are doing this often (e.g. when running GDB from a script), you might want to consider the following arguments to automate things further. First, you can place your GDB commands (such as 'run') in a text file and provide the filename to the -x argument. Second, you can have GDB exit after running your commands by providing the --batch argument. A full example: gdb -x commands.txt --batch --args executablename arg1 arg2 arg3

Lima Ubuntu VM setup on Mac

Homebrew Installation /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" Uninstallation /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)" Lima  launches Linux virtual machines with automatic file sharing and port forwarding (similar to WSL2). # Install brew install lima # Create VM limactl create --cpus=8 --memory=8 --name=default template://ubuntu limactl list # Start && Enter limactl start default limactl shell default # Stop limactl stop default # Delete limactl delete default # Protect && Unprotect limactl protect default limactl unprotect default # Copy # Host -> VM limactl cp ~/Downloads/test.png default:/tmp # VM -> Host…

How to run SPEC CPU2017 and disable checksum

1. Environment Preparation ​Install Dependencies: For Ubuntu/Debian (ARM cross-compilation example): sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu gfortran-aarch64-linux-gnu Ensure ulimit is set to unlimited: ulimit -s unlimited 2. Install SPEC CPU2017 ​Mount the ISO File: mount -o loop cpu2017-1.1.5.iso /mnt # Mount ISO to /mnt mkdir /home/speccpu cp /mnt/* -r /home/speccpu # Copy files to installation directory chmod -R 755 /home/speccpu # Set permissions Run Installation Script: cd /home/speccpu ./install.sh # Follow prompts and confirm with "yes" 3. Configure the Test Environment ​Modify the Configuration File: Copy the default config (e.g., Example-gcc-linux-aarch64.cfg) and…

Enabling PAC and BTI on AArch64 for Linux

Source code for the examples can be found at https://gitlab.arm.com/pac-and-bti-blog/blog-example and the tag will be referenced with the "Tag" keyword before source examples. Certain versions of Arm 64-bit processors have features that can help provide control flow integrity and reduce gadget space, making software more robust in the face of attack. Pointer Authentication Codes (PAC) work by signing and verifying indirect branch targets and branch target instructions (BTI) function by marking all valid branch locations. These technologies harden the control flow by ensuring that modification of control flow…

Running arm64 docker container on x86

Make sure to install the packages mentioned in , which then will allows docker to leverage qemu, which then emulates the target cpu architecture. binfmt Use the  image to install QEMU and register the executable types on the host with a single command: $ docker run --privileged --rm tonistiigi/binfmt --install all This installs the QEMU binaries and registers them with , enabling QEMU to execute non-native file formats for emulation. Once QEMU is installed and the executable types are registered on the host OS, they work transparently inside containers. You can…

A Quick and Easy Guide to tmux

I love working with the command line. I think there’s hardly any more productive and versatile tool for a software developer than the terminal. The additional hacker/wizard/neckbeard kind of feeling you get when using a terminal comes for free, what’s not to love? Over the years I’ve tried to streamline and customize my command line experience to be more convenient, more fun to use or just to look rad. One of the most important tools to drive my daily command line experience is tmux. Check this out: This screenshot…

Everything I know about GNU toolchain

As mainly an LLVM person, I occasionally contribute to GNU toolchain projects. This is sometimes for fun, sometimes for investigating why an (usually ancient) feature works in a particular way, sometimes for pushing forward a toolchain feature with the mind of both communities, or sometimes just for getting sense of how things work with mailing list+GNU make. For a debug build, I normally place my build directory out/debug directly under the project root. Dependency chain of a port: GCC needs binutils. Linux kernel needs GCC. glibc needs Linux kernel. binutils…

How to compile coreutils / binutils for aarch64 in x64

Dockcross git clone https://github.com/dockcross/dockcross.git cd dockcross docker run --rm dockcross/linux-arm64> ./dockcross-linux-arm64 chmod +x ./dockcross-linux-arm64 mv ./dockcross-linux-arm64 ~/bin/ Coreutils / Binutils //Go to the repository diretory dockcross-linux-arm64 bash //In the docker work diretory ./bootstrap(only for coreutils) mkdir aarch64 cd aarch64 ../configure make make check(run official test) Building GDB Natively Ever since the GDB and the binutils repositories were integrated (due to the git migration), it has become a bit more complex to build GDB. Of course, you can still do a simple ./configure && make, but you might actually want to disable…

How to launch ARM aarch64 VM with QEMU from scratch

The below instructions will allow for bringing up an ARM VM from scratch. To launch an aarch64 VM we first need to install a few dependencies, including QEMU and the qemu-efi-aarch64 package, which includes the efi firmware. apt-get install qemu-system-arm apt-get install qemu-efi-aarch64 apt-get install qemu-utils Create the flash images with the correct sizes. dd if=/dev/zero of=flash1.img bs=1M count=64 dd if=/dev/zero of=flash0.img bs=1M count=64 dd if=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd of=flash0.img conv=notrunc Create a dedicated directory (folder) on your host system to contain this virtual machine. Download the latest  “Virtual” ISO file for…