News for hackers. Stuff that matters.
Re:Clang's -O0 output: branch displacement and size increase by mkup on Saturday April 27, 2024 @06:31AM (#40178871)
NASM has an option (-Ox) to specify how many passes it should take trying to optimize near jumps for short jumps. I usually specify -O9.
Re:Clang's -O0 output: branch displacement and size increase by MaskRay on Sunday April 28, 2024 @02:04PM (#40190450)
Thanks for mentioning nasm.

Both GNU assembler and LLVM integrate assembler parse and match instructions only once. hey then store an internal representation in memory and perform fixed-point iteration. The section/fragment representation gives a lot of flexibility.

In contrast, nasm parses and matches instructions multiple times depending on the optimization level. It also assigns addresses during parsing and uses an ad-hoc method for JMP/JCC instructions. The end conditions of the fixed-point iteration algorithm (global_offset_changed and stall_count) seem unconventional. -O0 does not "relax all" short jumps to near jumps.