* Remove unused variables
Remove unused variables is_arithmetic, is_flag and size
from various files to address compiler warnings.
```
/usr/src/RPM/BUILD/liblief-0.17.0/api/python/src/enums_wrapper.hpp:42:20:
warning: unused variable ‘is_arithmetic’ [-Wunused-variable]
42 | constexpr bool is_arithmetic = (std::is_same_v<nanobind::is_arithmetic, Extra> || ...);
| ^~~~~~~~~~~~~
/usr/src/RPM/BUILD/liblief-0.17.0/api/python/src/enums_wrapper.hpp:43:20:
warning: unused variable ‘is_flag’ [-Wunused-variable]
43 | constexpr bool is_flag = (std::is_same_v<nanobind::is_flag, Extra> || ...);
| ^~~~~~~
/usr/src/RPM/BUILD/liblief-0.17.0/api/python/src/nanobind/extra/stl/u16string.h:15:20:
warning: unused variable ‘size’ [-Wunused-variable]
15 | Py_ssize_t size;
| ^~~~
```
* Fix(asm): Provide namespace-scope declarations for Operand::Iterator op==
Resolves compiler warnings by adding forward declarations for
`LIEF::assembly::{arch}::operator==(const Operand::Iterator&, const Operand::Iterator&)`
in the corresponding header files. The operators were previously only
declared via `friend` declarations inside the Iterator class.
```
[646/872] Building CXX object CMakeFiles/LIB_LIEF.dir/src/asm/asm.cpp.o
/usr/src/RPM/BUILD/liblief-0.17.0/src/asm/asm.cpp:395:6:
warning: ‘bool LIEF::assembly::x86::operator==(const Operand::Iterator&, const Operand::Iterator&)’
has not been declared within ‘LIEF::assembly::x86’
395 | bool x86::operator==(const x86::Operand::Iterator&, const x86::Operand::Iterator&) {
| ^~~
In file included from /usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/asm/x86/Instruction.hpp:21,
from /usr/src/RPM/BUILD/liblief-0.17.0/src/asm/asm.cpp:27:
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/asm/x86/Operand.hpp:60:26: note: only here as a ‘friend’
60 | friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
| ^~~~~~~~
/usr/src/RPM/BUILD/liblief-0.17.0/src/asm/asm.cpp:490:6:
warning: ‘bool LIEF::assembly::aarch64::operator==(const Operand::Iterator&, const Operand::Iterator&)’
has not been declared within ‘LIEF::assembly::aarch64’
490 | bool aarch64::operator==(const aarch64::Operand::Iterator&, const aarch64::Operand::Iterator&) {
| ^~~~~~~
In file included from /usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/asm/aarch64/Instruction.hpp:21,
from /usr/src/RPM/BUILD/liblief-0.17.0/src/asm/asm.cpp:18:
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/asm/aarch64/Operand.hpp:60:26: note: only here as a ‘friend’
60 | friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
| ^~~~~~~~
```
* Fix MachO ChainedPointerAnalysis pointer interpretation issues
Addresses strict aliasing warnings in getter methods by replacing
`reinterpret_cast` with `memcpy` and returning structures by value.
```
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/MachO/ChainedPointerAnalysis.hpp:
In member function ‘const LIEF::MachO::ChainedPointerAnalysis::dyld_chained_ptr_arm64e_rebase_t
LIEF::MachO::ChainedPointerAnalysis::dyld_chained_ptr_arm64e_rebase() const’:
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/MachO/ChainedPointerAnalysis.hpp:307:13:
warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
307 | return *reinterpret_cast<const dyld_chained_ptr_arm64e_rebase_t*>(&value_);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/MachO/ChainedPointerAnalysis.hpp:
In member function ‘const LIEF::MachO::ChainedPointerAnalysis::dyld_chained_ptr_32_firmware_rebase_t
LIEF::MachO::ChainedPointerAnalysis::dyld_chained_ptr_32_firmware_rebase() const’:
/usr/src/RPM/BUILD/liblief-0.17.0/include/LIEF/MachO/ChainedPointerAnalysis.hpp:355:13:
warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
355 | return *reinterpret_cast<const dyld_chained_ptr_32_firmware_rebase_t*>(&value_);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
* Fix PE layout check sign comparison for section index
Addresses Werror=sign-compare in LayoutChecker::check_load_config by
correctly handling potentially negative section index value when
comparing with vector size.
```
/usr/src/RPM/BUILD/liblief-0.17.0/src/PE/layout_check.cpp:447:22:
warning: comparison of integer expressions of different signedness:
‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
447 | if ((*value - 1) >= pe.sections().size()) {
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
```
* Fix PE: Rename conflicting local reloc_t structs
Renames local struct 'reloc_t' in DynamicFixupARM64Kernel.cpp and
DynamicFixupControlTransfer.cpp to 'arm64e_kernel_reloc_t' and
'control_transfer_reloc_t' respectively to fix One Definition Rule violations.
```
/usr/src/RPM/BUILD/liblief-0.17.0/src/PE/LoadConfigurations/DynamicRelocation/DynamicFixupARM64Kernel.cpp:35:
warning: type ‘struct reloc_t’ violates the C++ One Definition Rule [-Wodr]
35 | struct reloc_t {
/usr/src/RPM/BUILD/liblief-0.17.0/src/PE/LoadConfigurations/DynamicRelocation/DynamicFixupControlTransfer.cpp:31:
note: a different type is defined in another translation unit
31 | struct reloc_t {
```
* Add getters for the register count
* Add tests for the getter for the number of registers
* Fix: use const ref to avoid unecessary copy
---------
Co-authored-by: willboka <willbaka>
* MachO::Binary::add_section: respect alignment of empty sections
* MachO/layout_check: relax offset continuity requirement for __text section
Sections in MachO are prepended, but __text section is not moved.
Due to this there might be redundant gap between __text section and a
section that comes before __text.
Note: we don't want to alter distance between __DATA and __text, because
there might be position relative references in metadata.
* tests/macho: use lief.MachO.check_layout
* MachO::binary: add extend_section
This commit adds member function MachO::Binary::extend_section that is
able to extend sections from the first segment in MachO.
* macho/test_builder: add test_extend_section