facebookarchive / BOLT

Binary Optimization and Layout Tool - A linux command-line utility used for optimizing performance of binaries
2.51k stars 177 forks source link

Why add some nop after the method? when did BOLT add these nops? #289

Closed CcWeapon closed 2 years ago

CcWeapon commented 2 years ago

I want to use “-use-old-text” to reuse .text when I don't use any optimizations. There was only one fake entry in the null.fdata. e.g: ~/cpu-bolt/build/bin/llvm-bolt libxx.so -o libxx.bolt.none -data=null.fdata -reorder-blocks=none -reorder-functions=none -split-functions=0 -dyno-stats -use-old-text -v=1

then , bolt log say BOLT-WARNING: original .text too small to fit the new code using 0x1000 alignment. 2400776 bytes needed, have 2354072 bytes available.

i find bolt add some nop after the method. can u tell me why bolt do this, and when do bolt add these nops? image

CcWeapon commented 2 years ago

cc @rafaelauler @maksfb @aaupov

thx!!

getianao commented 2 years ago

I guess it's because of the alignment of function or section. You can try to adjust the value like https://github.com/facebookincubator/BOLT/blob/88c70afe9d388ad430cc150cc158641701397f70/bolt/include/bolt/Core/BinaryFunction.h#L181 or options like --align-text, --align-functions, --block-alignment.

CcWeapon commented 2 years ago

I guess it's because of the alignment of function or section. You can try to adjust the value like

https://github.com/facebookincubator/BOLT/blob/88c70afe9d388ad430cc150cc158641701397f70/bolt/include/bolt/Core/BinaryFunction.h#L181

or options like --align-text, --align-functions, --block-alignment.

It doesn't work. --align-functions mast >0, so i set it to 1, then bolt log say : BOLT-WARNING: original .text too small to fit the new code using 0x1000 alignment. 2354092 bytes needed, have 2354072 bytes available. The required space is smaller, but still larger than the original space.

maksfb commented 2 years ago

We always align the new .text at a page boundary. Historically, it was done for performance reasons. If the goal is to modify the binary for other reasons, it makes sense to remove the alignment. You can add a patch. Note that for C++, you need a 2-byte minimum alignment for functions for correctness reasons.

CcWeapon commented 2 years ago

thx