Skip to content

Commit 04f53eb

Browse files
committed
Merge branch 'bitcoin' into auxpow
2 parents 8943a2e + 2def858 commit 04f53eb

File tree

209 files changed

+1667
-1433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+1667
-1433
lines changed

.github/ci-test-each-commit-exec.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or https://opensource.org/license/mit/.
5+
6+
import subprocess
7+
import sys
8+
import shlex
9+
10+
11+
def run(cmd, **kwargs):
12+
print("+ " + shlex.join(cmd), flush=True)
13+
try:
14+
return subprocess.run(cmd, check=True, **kwargs)
15+
except Exception as e:
16+
sys.exit(e)
17+
18+
19+
def main():
20+
print("Running test-one-commit on ...")
21+
run(["git", "log", "-1"])
22+
23+
num_procs = int(run(["nproc"], stdout=subprocess.PIPE).stdout)
24+
25+
# Use clang++, because it is a bit faster and uses less memory than g++
26+
run([
27+
"cmake",
28+
"-B",
29+
"build",
30+
"-DCMAKE_C_COMPILER=clang",
31+
"-DCMAKE_CXX_COMPILER=clang++",
32+
"-DWERROR=ON",
33+
"-DWITH_ZMQ=ON",
34+
"-DBUILD_GUI=ON",
35+
"-DBUILD_BENCH=ON",
36+
"-DBUILD_FUZZ_BINARY=ON",
37+
"-DWITH_USDT=ON",
38+
"-DCMAKE_CXX_FLAGS=-Wno-error=unused-member-function",
39+
])
40+
run(["cmake", "--build", "build", "-j", str(num_procs)])
41+
run([
42+
"ctest",
43+
"--output-on-failure",
44+
"--stop-on-failure",
45+
"--test-dir",
46+
"build",
47+
"-j",
48+
str(num_procs),
49+
])
50+
run([
51+
sys.executable,
52+
"./build/test/functional/test_runner.py",
53+
"-j",
54+
str(num_procs * 2),
55+
"--combinedlogslen=99999999",
56+
])
57+
58+
59+
if __name__ == "__main__":
60+
main()

.github/ci-test-each-commit-exec.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) 2023-present The Bitcoin Core developers
22
# Distributed under the MIT software license, see the accompanying
3-
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
3+
# file COPYING or https://opensource.org/license/mit.
44

55
name: CI
66
on:
@@ -81,7 +81,7 @@ jobs:
8181
- name: Compile and run tests
8282
run: |
8383
# Run tests on commits after the last merge commit and before the PR head commit
84-
git rebase --exec "git merge --no-commit origin/${GITHUB_BASE_REF} && ./.github/ci-test-each-commit-exec.sh && git reset --hard" ${{ env.TEST_BASE }}
84+
git rebase --exec "git merge --no-commit origin/${GITHUB_BASE_REF} && python3 ./.github/ci-test-each-commit-exec.py && git reset --hard" ${{ env.TEST_BASE }}
8585
8686
macos-native-arm64:
8787
name: ${{ matrix.job-name }}

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ fixes or code moves with actual code changes.
115115

116116
Make sure each individual commit is hygienic: that it builds successfully on its
117117
own without warnings, errors, regressions, or test failures.
118+
This means tests must be updated in the same commit that changes the behavior.
118119

119120
Commit messages should be verbose by default consisting of a short subject line
120121
(50 chars max), a blank line and detailed explanatory text as separate

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ in Python.
5656
These tests can be run (if the [test dependencies](/test) are installed) with: `build/test/functional/test_runner.py`
5757
(assuming `build` is your build directory).
5858

59-
The CI (Continuous Integration) systems make sure that every pull request is built for Windows, Linux, and macOS,
60-
and that unit/sanity tests are run automatically.
59+
The CI (Continuous Integration) systems make sure that every pull request is tested on Windows, Linux, and macOS.
60+
The CI must pass on all commits before merge to avoid unrelated CI failures on new pull requests.
6161

6262
### Manual Quality Assurance (QA) Testing
6363

ci/lint/04_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ python3 --version
3838

3939
${CI_RETRY_EXE} pip3 install \
4040
codespell==2.4.1 \
41-
lief==0.13.2 \
41+
lief==0.16.6 \
4242
mypy==1.4.1 \
4343
pyzmq==25.1.0 \
4444
ruff==0.5.5 \

contrib/guix/guix-build

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ fi
6969

7070
mkdir -p "$VERSION_BASE"
7171

72+
################
73+
# SOURCE_DATE_EPOCH should not unintentionally be set
74+
################
75+
76+
if [ -n "$SOURCE_DATE_EPOCH" ] && [ -z "$FORCE_SOURCE_DATE_EPOCH" ]; then
77+
cat << EOF
78+
ERR: Environment variable SOURCE_DATE_EPOCH is set which may break reproducibility.
79+
80+
Aborting...
81+
82+
Hint: You may want to:
83+
1. Unset this variable: \`unset SOURCE_DATE_EPOCH\` before rebuilding
84+
2. Set the 'FORCE_SOURCE_DATE_EPOCH' environment variable if you insist on
85+
using your own epoch
86+
EOF
87+
exit 1
88+
fi
89+
7290
################
7391
# Build directories should not exist
7492
################

contrib/guix/manifest.scm

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
(gnu packages ninja)
1616
(gnu packages pkg-config)
1717
((gnu packages python) #:select (python-minimal))
18-
((gnu packages python-build) #:select (python-tomli python-poetry-core))
18+
((gnu packages python-build) #:select (python-poetry-core))
1919
((gnu packages python-crypto) #:select (python-asn1crypto))
20+
((gnu packages python-science) #:select (python-scikit-build-core))
21+
((gnu packages python-xyz) #:select (python-pydantic-2 python-pydantic-core))
2022
((gnu packages tls) #:select (openssl))
2123
((gnu packages version-control) #:select (git-minimal))
2224
(guix build-system cmake)
@@ -158,37 +160,35 @@ chain for " target " development."))
158160
(define-public python-lief
159161
(package
160162
(name "python-lief")
161-
(version "0.13.2")
163+
(version "0.16.6")
162164
(source (origin
163165
(method git-fetch)
164166
(uri (git-reference
165167
(url "https://github.com/lief-project/LIEF")
166168
(commit version)))
167169
(file-name (git-file-name name version))
168-
(modules '((guix build utils)))
169-
(snippet
170-
'(begin
171-
;; Configure build for Python bindings.
172-
(substitute* "api/python/config-default.toml"
173-
(("(ninja = )true" all m)
174-
(string-append m "false"))
175-
(("(parallel-jobs = )0" all m)
176-
(string-append m (number->string (parallel-job-count)))))))
177170
(sha256
178171
(base32
179-
"0y48x358ppig5xp97ahcphfipx7cg9chldj2q5zrmn610fmi4zll"))))
180-
(build-system python-build-system)
181-
(native-inputs (list cmake-minimal python-tomli))
172+
"1pq9nagrnkl1x943bqnpiyxmkd9vk99znfxiwqp6vf012b50bz2a"))
173+
(patches (search-our-patches "lief-scikit-0-9.patch"))))
174+
(build-system pyproject-build-system)
175+
(native-inputs (list cmake-minimal
176+
ninja
177+
python-scikit-build-core
178+
python-pydantic-core
179+
python-pydantic-2))
182180
(arguments
183181
(list
184182
#:tests? #f ;needs network
185183
#:phases #~(modify-phases %standard-phases
186-
(add-before 'build 'change-directory
184+
(add-before 'build 'set-pythonpath
187185
(lambda _
188-
(chdir "api/python")))
189-
(replace 'build
186+
(setenv "PYTHONPATH"
187+
(string-append (string-append (getcwd) "/api/python/backend")
188+
":" (or (getenv "PYTHONPATH") "")))))
189+
(add-after 'set-pythonpath 'change-directory
190190
(lambda _
191-
(invoke "python" "setup.py" "build"))))))
191+
(chdir "api/python"))))))
192192
(home-page "https://github.com/lief-project/LIEF")
193193
(synopsis "Library to instrument executable formats")
194194
(description
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Partially revert f23ced2f4ffc170d0a6f40ff4a1bee575e3447cf
2+
3+
Restore compat with python-scikit-build-core 0.9.x
4+
Can be dropped when using python-scikit-build-core >= 0.10.x
5+
6+
--- a/api/python/backend/setup.py
7+
+++ b/api/python/backend/setup.py
8+
@@ -101,12 +101,12 @@ def _get_hooked_config(is_editable: bool) -> Optional[dict[str, Union[str, List[
9+
config_settings = {
10+
"logging.level": "DEBUG",
11+
"build-dir": config.build_dir,
12+
- "build.targets": config.build.targets,
13+
"install.strip": config.strip,
14+
"backport.find-python": "0",
15+
"wheel.py-api": config.build.py_api,
16+
"cmake.source-dir": SRC_DIR.as_posix(),
17+
"cmake.build-type": config.build.build_type,
18+
+ "cmake.targets": config.build.targets,
19+
"cmake.args": [
20+
*config.cmake_generator,
21+
*config.get_cmake_args(is_editable),

contrib/guix/security-check.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ def check_ELF_RELRO(binary) -> bool:
3030
# However, the dynamic linker need to write to this area so these are RW.
3131
# Glibc itself takes care of mprotecting this area R after relocations are finished.
3232
# See also https://marc.info/?l=binutils&m=1498883354122353
33-
if segment.type == lief.ELF.SEGMENT_TYPES.GNU_RELRO:
33+
if segment.type == lief.ELF.Segment.TYPE.GNU_RELRO:
3434
have_gnu_relro = True
3535

3636
have_bindnow = False
3737
try:
38-
flags = binary.get(lief.ELF.DYNAMIC_TAGS.FLAGS)
39-
if flags.value & lief.ELF.DYNAMIC_FLAGS.BIND_NOW:
38+
flags = binary.get(lief.ELF.DynamicEntry.TAG.FLAGS)
39+
if flags.has(lief.ELF.DynamicEntryFlags.FLAG.BIND_NOW):
4040
have_bindnow = True
4141
except Exception:
4242
have_bindnow = False
@@ -55,9 +55,9 @@ def check_ELF_SEPARATE_CODE(binary):
5555
based on their permissions. This checks for missing -Wl,-z,separate-code
5656
and potentially other problems.
5757
'''
58-
R = lief.ELF.SEGMENT_FLAGS.R
59-
W = lief.ELF.SEGMENT_FLAGS.W
60-
E = lief.ELF.SEGMENT_FLAGS.X
58+
R = lief.ELF.Segment.FLAGS.R
59+
W = lief.ELF.Segment.FLAGS.W
60+
E = lief.ELF.Segment.FLAGS.X
6161
EXPECTED_FLAGS = {
6262
# Read + execute
6363
'.init': R | E,
@@ -99,7 +99,7 @@ def check_ELF_SEPARATE_CODE(binary):
9999
# and for each section, remember the flags of the associated program header.
100100
flags_per_section = {}
101101
for segment in binary.segments:
102-
if segment.type == lief.ELF.SEGMENT_TYPES.LOAD:
102+
if segment.type == lief.ELF.Segment.TYPE.LOAD:
103103
for section in segment.sections:
104104
flags_per_section[section.name] = segment.flags
105105
# Spot-check ELF LOAD program header flags per section
@@ -144,13 +144,13 @@ def check_ELF_FORTIFY(binary) -> bool:
144144

145145
def check_PE_DYNAMIC_BASE(binary) -> bool:
146146
'''PIE: DllCharacteristics bit 0x40 signifies dynamicbase (ASLR)'''
147-
return lief.PE.DLL_CHARACTERISTICS.DYNAMIC_BASE in binary.optional_header.dll_characteristics_lists
147+
return lief.PE.OptionalHeader.DLL_CHARACTERISTICS.DYNAMIC_BASE in binary.optional_header.dll_characteristics_lists
148148

149149
# Must support high-entropy 64-bit address space layout randomization
150150
# in addition to DYNAMIC_BASE to have secure ASLR.
151151
def check_PE_HIGH_ENTROPY_VA(binary) -> bool:
152152
'''PIE: DllCharacteristics bit 0x20 signifies high-entropy ASLR'''
153-
return lief.PE.DLL_CHARACTERISTICS.HIGH_ENTROPY_VA in binary.optional_header.dll_characteristics_lists
153+
return lief.PE.OptionalHeader.DLL_CHARACTERISTICS.HIGH_ENTROPY_VA in binary.optional_header.dll_characteristics_lists
154154

155155
def check_PE_RELOC_SECTION(binary) -> bool:
156156
'''Check for a reloc section. This is required for functional ASLR.'''
@@ -181,7 +181,7 @@ def check_MACHO_NOUNDEFS(binary) -> bool:
181181
'''
182182
Check for no undefined references.
183183
'''
184-
return binary.header.has(lief.MachO.HEADER_FLAGS.NOUNDEFS)
184+
return binary.header.has(lief.MachO.Header.FLAGS.NOUNDEFS)
185185

186186
def check_MACHO_FIXUP_CHAINS(binary) -> bool:
187187
'''
@@ -206,7 +206,13 @@ def check_NX(binary) -> bool:
206206
'''
207207
Check for no stack execution
208208
'''
209-
return binary.has_nx
209+
210+
# binary.has_nx checks are only for the stack, but MachO binaries might
211+
# have executable heaps.
212+
if binary.format == lief.Binary.FORMATS.MACHO:
213+
return binary.concrete.has_nx_stack and binary.concrete.has_nx_heap
214+
else:
215+
return binary.has_nx
210216

211217
def check_MACHO_CONTROL_FLOW(binary) -> bool:
212218
'''
@@ -229,6 +235,7 @@ def check_MACHO_BRANCH_PROTECTION(binary) -> bool:
229235
return False
230236

231237
BASE_ELF = [
238+
('FORTIFY', check_ELF_FORTIFY),
232239
('PIE', check_PIE),
233240
('NX', check_NX),
234241
('RELRO', check_ELF_RELRO),
@@ -253,31 +260,31 @@ def check_MACHO_BRANCH_PROTECTION(binary) -> bool:
253260
]
254261

255262
CHECKS = {
256-
lief.EXE_FORMATS.ELF: {
257-
lief.ARCHITECTURES.X86: BASE_ELF + [('CONTROL_FLOW', check_ELF_CONTROL_FLOW), ('FORTIFY', check_ELF_FORTIFY)],
258-
lief.ARCHITECTURES.ARM: BASE_ELF + [('FORTIFY', check_ELF_FORTIFY)],
259-
lief.ARCHITECTURES.ARM64: BASE_ELF + [('FORTIFY', check_ELF_FORTIFY)],
260-
lief.ARCHITECTURES.PPC: BASE_ELF + [('FORTIFY', check_ELF_FORTIFY)],
261-
lief.ARCHITECTURES.RISCV: BASE_ELF, # Skip FORTIFY. See https://github.com/lief-project/LIEF/issues/1082.
263+
lief.Binary.FORMATS.ELF: {
264+
lief.Header.ARCHITECTURES.X86_64: BASE_ELF + [('CONTROL_FLOW', check_ELF_CONTROL_FLOW)],
265+
lief.Header.ARCHITECTURES.ARM: BASE_ELF,
266+
lief.Header.ARCHITECTURES.ARM64: BASE_ELF,
267+
lief.Header.ARCHITECTURES.PPC64: BASE_ELF,
268+
lief.Header.ARCHITECTURES.RISCV: BASE_ELF,
262269
},
263-
lief.EXE_FORMATS.PE: {
264-
lief.ARCHITECTURES.X86: BASE_PE,
270+
lief.Binary.FORMATS.PE: {
271+
lief.Header.ARCHITECTURES.X86_64: BASE_PE,
265272
},
266-
lief.EXE_FORMATS.MACHO: {
267-
lief.ARCHITECTURES.X86: BASE_MACHO + [('PIE', check_PIE),
273+
lief.Binary.FORMATS.MACHO: {
274+
lief.Header.ARCHITECTURES.X86_64: BASE_MACHO + [('PIE', check_PIE),
268275
('NX', check_NX),
269276
('CONTROL_FLOW', check_MACHO_CONTROL_FLOW)],
270-
lief.ARCHITECTURES.ARM64: BASE_MACHO + [('BRANCH_PROTECTION', check_MACHO_BRANCH_PROTECTION)],
277+
lief.Header.ARCHITECTURES.ARM64: BASE_MACHO + [('BRANCH_PROTECTION', check_MACHO_BRANCH_PROTECTION)],
271278
}
272279
}
273280

274281
if __name__ == '__main__':
275282
retval: int = 0
276283
for filename in sys.argv[1:]:
277284
binary = lief.parse(filename)
285+
278286
etype = binary.format
279287
arch = binary.abstract.header.architecture
280-
binary.concrete
281288

282289
failed: list[str] = []
283290
for (name, func) in CHECKS[etype][arch]:

0 commit comments

Comments
 (0)