Build System Overview
Stardust uses a GNU Make-based build system that orchestrates compilation across multiple architectures and toolchains. The build process involves:- Assembly compilation (NASM) for entry stubs
- C++ compilation (Clang) for main logic
- Linking with custom linker script for PIC
- Section extraction (objcopy) to produce raw shellcode
Makefile Targets
Primary Targets
Architecture-Specific Targets
Compiler Configuration
Toolchain Selection
Stardust uses Clang with MinGW targets for cross-platform Windows compilation:Makefile
Clang provides better C++20 support (particularly
consteval) and more predictable optimization behavior compared to GCC for shellcode development.Core Compiler Flags
Makefile
Optimization Flags
| Flag | Purpose |
|---|---|
-Os | Optimize for size (critical for shellcode) |
-ffunction-sections | Place each function in its own section for better dead code elimination |
-falign-functions=1 | Minimize function alignment padding (save bytes) |
-falign-jumps=1 | Minimize jump target alignment |
-falign-labels=1 | Minimize label alignment |
Position Independence Flags
| Flag | Purpose |
|---|---|
-fPIC | Generate position-independent code |
-nostdlib | Don’t link standard library (avoid dependencies) |
-fno-asynchronous-unwind-tables | Remove unwind tables (not needed for shellcode) |
-fno-ident | Remove compiler identification strings |
Windows-Specific Flags
| Flag | Purpose |
|---|---|
-fms-extensions | Enable Microsoft C extensions |
-masm=intel | Use Intel assembly syntax |
-fpack-struct=8 | Pack structures to 8-byte alignment |
-Wl,--enable-stdcall-fixup | Fix stdcall symbol mangling |
-Wl,--no-seh | Disable structured exception handling |
Security/Cleanup Flags
| Flag | Purpose |
|---|---|
-s | Strip symbol table |
-Wl,-s | Strip symbols during linking |
-w | Suppress all warnings (for clean build output) |
-mno-sse | Disable SSE instructions (reduces complexity) |
-fno-exceptions | Disable C++ exceptions |
Build Modes
Release Mode
Command:make or make release
Characteristics:
- Maximum size optimization
- No debug symbols
DBG_PRINTFmacros compile to no-ops- Typical output: ~750 bytes (x64), ~670 bytes (x86)
include/common.h
Debug Mode
Command:make debug
Characteristics:
- Adds
-D DEBUGpreprocessor flag - Includes
ntdll.DbgPrintfor kernel debugging - Resolves
DbgPrintAPI from ntdll - Typical output: ~1.2KB (x64), ~1.1KB (x86)
Download DebugView
Get DebugView from Sysinternals.
Enable Capture Options
- Check Capture -> Capture Kernel
- Check Capture -> Capture Win32
- Uncheck Capture -> Capture Events (reduces noise)
Linker Script
The custom linker script (scripts/linker.ld) controls section layout to ensure proper PIC generation:
scripts/linker.ld
Section Purposes
.text$A
Assembly entry point with stack alignment. Contains the
stardust symbol and RipStart helper..text$B
All C++ compiled code marked with
declfn attribute. This includes instance::instance() and instance::start()..rdata*
Read-only data including compile-time hashes and string literals used by
symbol<T>()..text$C
End-of-data marker provided by
RipData(). Used for calculating shellcode size at runtime.Custom Section Placement
Code can be placed in specific sections using thedeclfn macro:
include/macros.h
src/main.cc
Build Process Deep Dive
Step 1: Assembly Compilation
Makefile
entry.*.asm: Entry point with stack alignmentutils.*.asm: Position calculation helpers (RipStart,RipData)
src/asm/entry.x64.asm
Step 2: C++ Compilation
Makefile
.cc file is compiled to an object file with all optimization flags applied.
Step 3: Linking
Makefile
.text section is not tied to a specific base address (PIC requirement).
Step 4: Section Extraction
Makefile
objcopy extracts only the .text section, producing a raw binary file containing pure shellcode with no PE headers or metadata.
Output Files
Directory Structure
Binary Analysis
Inspect with hexdump:56:push rsi(entry stub)48 89 e6:mov rsi, rsp48 83 e4 f0:and rsp, 0xFFFFFFFFFFFFFFF0(stack alignment)
Customizing the Build
Adding Source Files
The Makefile automatically compiles all.cc files in src/:
Makefile
- Create
src/mycode.cc - Run
make(automatically detected)
Adjusting Optimization
For smaller binaries:Enabling Additional Warnings
Troubleshooting
Error: undefined reference to 'expr::hash_string'
Error: undefined reference to 'expr::hash_string'
Cause: The
consteval function is not being evaluated at compile-time.Solution:- Ensure you’re using Clang (not GCC)
- Verify C++20 is enabled:
-std=c++20 - Check that arguments to
expr::hash_stringare compile-time constants:
Shellcode larger than expected (>2KB)
Shellcode larger than expected (>2KB)
Causes:
- Debug mode enabled: Check if
-D DEBUGis in CFLAGS - Unused code not eliminated: Ensure
-ffunction-sectionsis set - Large string literals: Use
symbol<T>()for all strings
NASM error: symbol 'entry' undefined
NASM error: symbol 'entry' undefined
Cause: C++ name mangling prevents assembly from finding C++ functions.Solution:Ensure functions called from assembly use
extern "C":src/main.cc
Linker error: cannot find -lkernel32
Linker error: cannot find -lkernel32
Cause: Makefile is trying to link Windows libraries (not needed for shellcode).Solution:Verify
-nostdlib is in CFLAGS and no -l flags are specified:Advanced Techniques
Analyzing Generated Assembly
Review the assembly output to verify optimization:Profiling Shellcode Size
Track size changes across builds:Cross-Compilation from macOS
Install LLVM and MinGW:Next Steps
API Reference
Explore available functions and macros
Examples
See real-world shellcode implementations
Advanced Topics
Position calculation, string handling, and more
Core Concepts
Understand the Stardust architecture
