From ec2b999bfa8c3109d12c14d3aba70aed7cc7fb1e Mon Sep 17 00:00:00 2001 From: lb1107039128 Date: Thu, 21 Dec 2023 16:15:52 +0800 Subject: [PATCH 1/2] ecode functio Signed-off-by: lb1107039128 --- 0001-Call-relocation-for-ARM-V3-194.patch | 214 ++++++++++++++++++++++ pyelftools.spec | 7 +- 2 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 0001-Call-relocation-for-ARM-V3-194.patch diff --git a/0001-Call-relocation-for-ARM-V3-194.patch b/0001-Call-relocation-for-ARM-V3-194.patch new file mode 100644 index 0000000..ed162bb --- /dev/null +++ b/0001-Call-relocation-for-ARM-V3-194.patch @@ -0,0 +1,214 @@ +From f52f66634d1f9419239ce80ce455fea43ecc6aa7 Mon Sep 17 00:00:00 2001 +From: Dmitry Koltunov +Date: Wed, 5 Sep 2018 15:25:28 +0300 +Subject: [PATCH] Call relocation for ARM V3 (#194) + +* Add support for 'R_ARM_CALL' relocation type + +* Add test script and test files to verify support for 'R_ARM_CALL' + +Signed-off-by: Koltunov Dmitry +--- + elftools/elf/relocation.py | 6 ++ + test/run_arm_reloc_call_test.py | 62 ++++++++++++++++++ + .../reloc_simple_arm_llvm.o | Bin 0 -> 1488 bytes + test/testfiles_for_unittests/simple.c | 41 ++++++++++++ + .../simple_arm_llvm.elf | Bin 0 -> 34272 bytes + 5 files changed, 109 insertions(+) + create mode 100755 test/run_arm_reloc_call_test.py + create mode 100644 test/testfiles_for_unittests/reloc_simple_arm_llvm.o + create mode 100644 test/testfiles_for_unittests/simple.c + create mode 100755 test/testfiles_for_unittests/simple_arm_llvm.elf + +diff --git a/elftools/elf/relocation.py b/elftools/elf/relocation.py +index 6f2c4b4..59b6750 100644 +--- a/elftools/elf/relocation.py ++++ b/elftools/elf/relocation.py +@@ -219,10 +219,16 @@ class RelocationHandler(object): + def _reloc_calc_sym_plus_addend_pcrel(value, sym_value, offset, addend=0): + return sym_value + addend - offset + ++ def _arm_reloc_calc_sym_plus_value_pcrel(value, sym_value, offset, addend=0): ++ return sym_value / 4 + value - offset / 4 ++ + _RELOCATION_RECIPES_ARM = { + ENUM_RELOC_TYPE_ARM['R_ARM_ABS32']: _RELOCATION_RECIPE_TYPE( + bytesize=4, has_addend=False, + calc_func=_reloc_calc_sym_plus_value), ++ ENUM_RELOC_TYPE_ARM['R_ARM_CALL']: _RELOCATION_RECIPE_TYPE( ++ bytesize=4, has_addend=False, ++ calc_func=_arm_reloc_calc_sym_plus_value_pcrel), + } + + # https://dmz-portal.mips.com/wiki/MIPS_relocation_types +diff --git a/test/run_arm_reloc_call_test.py b/test/run_arm_reloc_call_test.py +new file mode 100755 +index 0000000..261949d +--- /dev/null ++++ b/test/run_arm_reloc_call_test.py +@@ -0,0 +1,62 @@ ++#!/usr/bin/env python ++#------------------------------------------------------------------------------- ++# test/run_arm_reloc_call_test.py ++# ++# Test 'R_ARM_CALL' relocation type support. ++# Compare the '.text' section data of ELF file that relocated by elftools ++# and ELF file that relocated by linker. ++# ++# Dmitry Koltunov (koltunov@ispras.ru) ++#------------------------------------------------------------------------------- ++from os.path import ( ++ join, ++ dirname ++) ++from sys import ( ++ exit ++) ++ ++from elftools.common.py3compat import ( ++ BytesIO ++) ++from elftools.elf.elffile import ( ++ ELFFile ++) ++from elftools.elf.relocation import ( ++ RelocationHandler ++) ++ ++ ++def do_relocation(rel_elf): ++ data = rel_elf.get_section_by_name('.text').data() ++ rh = RelocationHandler(rel_elf) ++ ++ stream = BytesIO() ++ stream.write(data) ++ ++ rel = rel_elf.get_section_by_name('.rel.text') ++ rh.apply_section_relocations(stream, rel) ++ ++ stream.seek(0) ++ data = stream.readlines() ++ ++ return data ++ ++ ++def main(): ++ test_dir = join(dirname(__file__) or '.', 'testfiles_for_unittests') ++ with open(join(test_dir, 'reloc_simple_arm_llvm.o'), 'rb') as rel_f, \ ++ open(join(test_dir, 'simple_arm_llvm.elf'), 'rb') as f: ++ rel_elf = ELFFile(rel_f) ++ elf = ELFFile(f) ++ ++ # Comparison of '.text' section data ++ if do_relocation(rel_elf).pop() != elf.get_section_by_name('.text').data(): ++ print 'FAIL' ++ return 1 ++ print 'OK' ++ return 0 ++ ++ ++if __name__ == '__main__': ++ exit(main()) +diff --git a/test/testfiles_for_unittests/reloc_simple_arm_llvm.o b/test/testfiles_for_unittests/reloc_simple_arm_llvm.o +new file mode 100644 +index 0000000000000000000000000000000000000000..a1bfbaa893443246d3da536c7f6685252c51827b +GIT binary patch +literal 1488 +zcmb7Ezi-n}5Wd&CC6ItjRYYm4VgZ5_sgCo*Ns1U+@vB42075Jbb!?|Z3tN17p+35{LzMMEEYTOBx{rCp~}neRsLL_nw`nw-#>;At*3G +zQTok@=A=$!DAj=|oj_FHT{;ko+a%3xMyTP11hY!ZbrQ`nPe0yyDCl&~jbuAlApR|!0%K*Rh3 +z^#)|O*{g^8b@1>m_Pp@!Gw-RlACcSQULR$*^=5Lj#XTG6-If^NY(?OAdrx?BU(G=8 +zpCQouX9#quua1nfKQbHcitkYKaoNY0K1v97?$|6E+1X^)Or~|y)HN%W&u0w7GP7nTJ5BR(jBVIPu0Y}n+#3m1 +zo26k95~t|27?DQB8F6-SOq>(r15?8n#O2=C7x_dFJJ0SzqVH{|hZ7APVT0iJeTC0& +z1Uw1kGu!rg7PySX-vr0m=iDHF5k8-F6^rBVfs^=-J~196`o=g+bQ3jMf5ZsgVTAsI +zF@z-8)j=Y58D$^Gd{lfSwPqL9`Fl&Myt-j;-Fg`(UQ-80Hf~Mzv^@VOdl!l;El+)mL+*)}5MTFm99>FBvLt_n*x| +zCbn>BA3!z^ng2e5k78l_gk$I!pRvn=Z{5G6?pYiUM4*Lwd@ro=jdC8J+YlChUVRQ^ +z+XIOLgIf>kaf{x1+o;ERtZ`0IZyY}72Alr@@)|raj`6zgW1znZ8u|j~uwBGLt7?bf +Y!Fh>*0E4_D{N56KAX|Psm`?`(1@iAQlK=n! + +literal 0 +HcmV?d00001 + +diff --git a/test/testfiles_for_unittests/simple.c b/test/testfiles_for_unittests/simple.c +new file mode 100644 +index 0000000..4ea1c67 +--- /dev/null ++++ b/test/testfiles_for_unittests/simple.c +@@ -0,0 +1,41 @@ ++/* Generated by compiling with any LLVM version and ++** with any GNU Arm Embedded Toolchain version. ++** LLVM 3.8.0/5.0.0 and GNU Arm Embedded Toolchain 2.26 is fine. ++** ++** clang -O0 --target=arm-none-eabi -emit-llvm -c simple.c -o simple.bc ++** llc -O0 -march=arm -filetype=obj simple.bc -o reloc_simple_arm_llvm.o ++** arm-none-eabi-ld -e main reloc_simple_arm_llvm.o -o simple_arm_llvm.elf ++** ++** reloc_simple_arm_llvm.o is ELF file that needs call relocation. ++** ++** simple_arm_llvm.elf is a relocated ELF file. ++*/ ++ ++int add(int a, int b) { ++ return a + b; ++} ++ ++int sub(int a, int b) { ++ return a - b; ++} ++ ++int mul(int a, int b) { ++ return a * b; ++} ++ ++void triple(int a, int b) { ++ add(a, b); ++ sub(a, b); ++ mul(a, b); ++} ++ ++int main(void) { ++ int a = 0xABCD, b = 0x1234; ++ ++ add(a, b); ++ sub(a, b); ++ mul(a, b); ++ triple(a, b); ++ ++ return 0; ++} +diff --git a/test/testfiles_for_unittests/simple_arm_llvm.elf b/test/testfiles_for_unittests/simple_arm_llvm.elf +new file mode 100755 +index 0000000000000000000000000000000000000000..f1cfbb8d6593d38281a49dc2cb8e2ccacb42ed8e +GIT binary patch +literal 34272 +zcmeIw&u`mg7zgm@P27^vAiN5+A4S8U0h<8FY2qe>3lkdbupU4hkT|4{?Q{`I8YS*j +zPD{33BXQukNxn>~gpiOpaX{i90QJC$Q?tkth!g+7!t>a%aH9&rf!p_$UcY{RP6#+G2A3#5m+$nJaNt +z(MM6>ooHADtGw!`6_A4f1Rwwb2tWV=5P$##AOHafKmY;|fB*y_009U<00Izz00bZa +z0SG_<0uX=z1Rwwb2tWV=5P$##AOHafKmY;|fB*y_009U<00Izz00bZa0SG_<0uX=z +z1Rwwb2tWV=5P$##AOHafKmY;|fB*y_009U<00Izz00bZa0SG_<0uX=z1Rwwb2tWV= +z5P$##AOHafKmY;|fB*y_009U<00Izz00bZa0SNrh0{YSR6J>-`vchSRCQ(73L`8bU +z>!V1~=vXr*5m}Q+KbkzbG%rp6x&OWY)c>U_9v3N`E&z|ACOg?*t?=yKhOM2!XIj^&Q +z_G~*(=XVu<18&FZ?HYId!LYs8Gi=i`E#u1VAn3nSDs?({y5`*{ik6)lIKfwyJ); +zQg?qjS8@@mC|FKCkQCe_^Tq2FJ3W#f#M6vsL#BIg8r!sdS95962omzNFhlYenl`bWtOlfP9m +zER~E`c;R&a9S8>BMIq| +yah7NHYyI>A(T%v0T+%*SvtRj$_uJv*Gn|)m%K3DjXLx4!JHAhJz`1m!`~3yEO<^Md + +literal 0 +HcmV?d00001 + +-- +2.42.0.windows.2 + diff --git a/pyelftools.spec b/pyelftools.spec index a760ca8..1c6a733 100644 --- a/pyelftools.spec +++ b/pyelftools.spec @@ -1,6 +1,6 @@ Name: pyelftools Version: 0.25 -Release: 3 +Release: 4 License: Public Domain Summary: Pure-Python library for parsing and analyzing ELF files URL: https://github.com/eliben/pyelftools @@ -9,6 +9,8 @@ Source0: https://files.pythonhosted.org/packages/source/p/pyelftools/pyel BuildRequires: python3-devel python3-setuptools BuildArch: noarch +Patch0001: 0001-Call-relocation-for-ARM-V3-194.patch + %description This package provides a python library for parsing and analyzing ELF files and DWARF debugging information. @@ -44,6 +46,9 @@ mv %{buildroot}/usr/bin/readelf.py %{buildroot}/usr/bin/pyreadelf %changelog +* Thu Dec 21 2023 liubo - 0.25-4 +- PYTHON-1918 Stop using BSON.encode and BSON.decode functions + * Mon Nov 16 2020 baizhonggui - 0.25-3 - Drop Python 2 subpackage -- Gitee From 8f41d34f9c1a248cd07e8222a7cb3fc1973ee686 Mon Sep 17 00:00:00 2001 From: lb1107039128 Date: Tue, 26 Dec 2023 14:49:31 +0800 Subject: [PATCH 2/2] Small stylistic fixes Signed-off-by: lb1107039128 --- 0001-Call-relocation-for-ARM-V3-194.patch | 214 ---------------------- 0001-Small-stylistic-fixes.patch | 131 +++++++++++++ pyelftools.spec | 6 +- 3 files changed, 134 insertions(+), 217 deletions(-) delete mode 100644 0001-Call-relocation-for-ARM-V3-194.patch create mode 100644 0001-Small-stylistic-fixes.patch diff --git a/0001-Call-relocation-for-ARM-V3-194.patch b/0001-Call-relocation-for-ARM-V3-194.patch deleted file mode 100644 index ed162bb..0000000 --- a/0001-Call-relocation-for-ARM-V3-194.patch +++ /dev/null @@ -1,214 +0,0 @@ -From f52f66634d1f9419239ce80ce455fea43ecc6aa7 Mon Sep 17 00:00:00 2001 -From: Dmitry Koltunov -Date: Wed, 5 Sep 2018 15:25:28 +0300 -Subject: [PATCH] Call relocation for ARM V3 (#194) - -* Add support for 'R_ARM_CALL' relocation type - -* Add test script and test files to verify support for 'R_ARM_CALL' - -Signed-off-by: Koltunov Dmitry ---- - elftools/elf/relocation.py | 6 ++ - test/run_arm_reloc_call_test.py | 62 ++++++++++++++++++ - .../reloc_simple_arm_llvm.o | Bin 0 -> 1488 bytes - test/testfiles_for_unittests/simple.c | 41 ++++++++++++ - .../simple_arm_llvm.elf | Bin 0 -> 34272 bytes - 5 files changed, 109 insertions(+) - create mode 100755 test/run_arm_reloc_call_test.py - create mode 100644 test/testfiles_for_unittests/reloc_simple_arm_llvm.o - create mode 100644 test/testfiles_for_unittests/simple.c - create mode 100755 test/testfiles_for_unittests/simple_arm_llvm.elf - -diff --git a/elftools/elf/relocation.py b/elftools/elf/relocation.py -index 6f2c4b4..59b6750 100644 ---- a/elftools/elf/relocation.py -+++ b/elftools/elf/relocation.py -@@ -219,10 +219,16 @@ class RelocationHandler(object): - def _reloc_calc_sym_plus_addend_pcrel(value, sym_value, offset, addend=0): - return sym_value + addend - offset - -+ def _arm_reloc_calc_sym_plus_value_pcrel(value, sym_value, offset, addend=0): -+ return sym_value / 4 + value - offset / 4 -+ - _RELOCATION_RECIPES_ARM = { - ENUM_RELOC_TYPE_ARM['R_ARM_ABS32']: _RELOCATION_RECIPE_TYPE( - bytesize=4, has_addend=False, - calc_func=_reloc_calc_sym_plus_value), -+ ENUM_RELOC_TYPE_ARM['R_ARM_CALL']: _RELOCATION_RECIPE_TYPE( -+ bytesize=4, has_addend=False, -+ calc_func=_arm_reloc_calc_sym_plus_value_pcrel), - } - - # https://dmz-portal.mips.com/wiki/MIPS_relocation_types -diff --git a/test/run_arm_reloc_call_test.py b/test/run_arm_reloc_call_test.py -new file mode 100755 -index 0000000..261949d ---- /dev/null -+++ b/test/run_arm_reloc_call_test.py -@@ -0,0 +1,62 @@ -+#!/usr/bin/env python -+#------------------------------------------------------------------------------- -+# test/run_arm_reloc_call_test.py -+# -+# Test 'R_ARM_CALL' relocation type support. -+# Compare the '.text' section data of ELF file that relocated by elftools -+# and ELF file that relocated by linker. -+# -+# Dmitry Koltunov (koltunov@ispras.ru) -+#------------------------------------------------------------------------------- -+from os.path import ( -+ join, -+ dirname -+) -+from sys import ( -+ exit -+) -+ -+from elftools.common.py3compat import ( -+ BytesIO -+) -+from elftools.elf.elffile import ( -+ ELFFile -+) -+from elftools.elf.relocation import ( -+ RelocationHandler -+) -+ -+ -+def do_relocation(rel_elf): -+ data = rel_elf.get_section_by_name('.text').data() -+ rh = RelocationHandler(rel_elf) -+ -+ stream = BytesIO() -+ stream.write(data) -+ -+ rel = rel_elf.get_section_by_name('.rel.text') -+ rh.apply_section_relocations(stream, rel) -+ -+ stream.seek(0) -+ data = stream.readlines() -+ -+ return data -+ -+ -+def main(): -+ test_dir = join(dirname(__file__) or '.', 'testfiles_for_unittests') -+ with open(join(test_dir, 'reloc_simple_arm_llvm.o'), 'rb') as rel_f, \ -+ open(join(test_dir, 'simple_arm_llvm.elf'), 'rb') as f: -+ rel_elf = ELFFile(rel_f) -+ elf = ELFFile(f) -+ -+ # Comparison of '.text' section data -+ if do_relocation(rel_elf).pop() != elf.get_section_by_name('.text').data(): -+ print 'FAIL' -+ return 1 -+ print 'OK' -+ return 0 -+ -+ -+if __name__ == '__main__': -+ exit(main()) -diff --git a/test/testfiles_for_unittests/reloc_simple_arm_llvm.o b/test/testfiles_for_unittests/reloc_simple_arm_llvm.o -new file mode 100644 -index 0000000000000000000000000000000000000000..a1bfbaa893443246d3da536c7f6685252c51827b -GIT binary patch -literal 1488 -zcmb7Ezi-n}5Wd&CC6ItjRYYm4VgZ5_sgCo*Ns1U+@vB42075Jbb!?|Z3tN17p+35{LzMMEEYTOBx{rCp~}neRsLL_nw`nw-#>;At*3G -zQTok@=A=$!DAj=|oj_FHT{;ko+a%3xMyTP11hY!ZbrQ`nPe0yyDCl&~jbuAlApR|!0%K*Rh3 -z^#)|O*{g^8b@1>m_Pp@!Gw-RlACcSQULR$*^=5Lj#XTG6-If^NY(?OAdrx?BU(G=8 -zpCQouX9#quua1nfKQbHcitkYKaoNY0K1v97?$|6E+1X^)Or~|y)HN%W&u0w7GP7nTJ5BR(jBVIPu0Y}n+#3m1 -zo26k95~t|27?DQB8F6-SOq>(r15?8n#O2=C7x_dFJJ0SzqVH{|hZ7APVT0iJeTC0& -z1Uw1kGu!rg7PySX-vr0m=iDHF5k8-F6^rBVfs^=-J~196`o=g+bQ3jMf5ZsgVTAsI -zF@z-8)j=Y58D$^Gd{lfSwPqL9`Fl&Myt-j;-Fg`(UQ-80Hf~Mzv^@VOdl!l;El+)mL+*)}5MTFm99>FBvLt_n*x| -zCbn>BA3!z^ng2e5k78l_gk$I!pRvn=Z{5G6?pYiUM4*Lwd@ro=jdC8J+YlChUVRQ^ -z+XIOLgIf>kaf{x1+o;ERtZ`0IZyY}72Alr@@)|raj`6zgW1znZ8u|j~uwBGLt7?bf -Y!Fh>*0E4_D{N56KAX|Psm`?`(1@iAQlK=n! - -literal 0 -HcmV?d00001 - -diff --git a/test/testfiles_for_unittests/simple.c b/test/testfiles_for_unittests/simple.c -new file mode 100644 -index 0000000..4ea1c67 ---- /dev/null -+++ b/test/testfiles_for_unittests/simple.c -@@ -0,0 +1,41 @@ -+/* Generated by compiling with any LLVM version and -+** with any GNU Arm Embedded Toolchain version. -+** LLVM 3.8.0/5.0.0 and GNU Arm Embedded Toolchain 2.26 is fine. -+** -+** clang -O0 --target=arm-none-eabi -emit-llvm -c simple.c -o simple.bc -+** llc -O0 -march=arm -filetype=obj simple.bc -o reloc_simple_arm_llvm.o -+** arm-none-eabi-ld -e main reloc_simple_arm_llvm.o -o simple_arm_llvm.elf -+** -+** reloc_simple_arm_llvm.o is ELF file that needs call relocation. -+** -+** simple_arm_llvm.elf is a relocated ELF file. -+*/ -+ -+int add(int a, int b) { -+ return a + b; -+} -+ -+int sub(int a, int b) { -+ return a - b; -+} -+ -+int mul(int a, int b) { -+ return a * b; -+} -+ -+void triple(int a, int b) { -+ add(a, b); -+ sub(a, b); -+ mul(a, b); -+} -+ -+int main(void) { -+ int a = 0xABCD, b = 0x1234; -+ -+ add(a, b); -+ sub(a, b); -+ mul(a, b); -+ triple(a, b); -+ -+ return 0; -+} -diff --git a/test/testfiles_for_unittests/simple_arm_llvm.elf b/test/testfiles_for_unittests/simple_arm_llvm.elf -new file mode 100755 -index 0000000000000000000000000000000000000000..f1cfbb8d6593d38281a49dc2cb8e2ccacb42ed8e -GIT binary patch -literal 34272 -zcmeIw&u`mg7zgm@P27^vAiN5+A4S8U0h<8FY2qe>3lkdbupU4hkT|4{?Q{`I8YS*j -zPD{33BXQukNxn>~gpiOpaX{i90QJC$Q?tkth!g+7!t>a%aH9&rf!p_$UcY{RP6#+G2A3#5m+$nJaNt -z(MM6>ooHADtGw!`6_A4f1Rwwb2tWV=5P$##AOHafKmY;|fB*y_009U<00Izz00bZa -z0SG_<0uX=z1Rwwb2tWV=5P$##AOHafKmY;|fB*y_009U<00Izz00bZa0SG_<0uX=z -z1Rwwb2tWV=5P$##AOHafKmY;|fB*y_009U<00Izz00bZa0SG_<0uX=z1Rwwb2tWV= -z5P$##AOHafKmY;|fB*y_009U<00Izz00bZa0SNrh0{YSR6J>-`vchSRCQ(73L`8bU -z>!V1~=vXr*5m}Q+KbkzbG%rp6x&OWY)c>U_9v3N`E&z|ACOg?*t?=yKhOM2!XIj^&Q -z_G~*(=XVu<18&FZ?HYId!LYs8Gi=i`E#u1VAn3nSDs?({y5`*{ik6)lIKfwyJ); -zQg?qjS8@@mC|FKCkQCe_^Tq2FJ3W#f#M6vsL#BIg8r!sdS95962omzNFhlYenl`bWtOlfP9m -zER~E`c;R&a9S8>BMIq| -yah7NHYyI>A(T%v0T+%*SvtRj$_uJv*Gn|)m%K3DjXLx4!JHAhJz`1m!`~3yEO<^Md - -literal 0 -HcmV?d00001 - --- -2.42.0.windows.2 - diff --git a/0001-Small-stylistic-fixes.patch b/0001-Small-stylistic-fixes.patch new file mode 100644 index 0000000..7479f97 --- /dev/null +++ b/0001-Small-stylistic-fixes.patch @@ -0,0 +1,131 @@ +From 55af257faeaca39b59a1a6cd9432c2aa2987e39e Mon Sep 17 00:00:00 2001 +From: Eli Bendersky +Date: Thu, 31 Jan 2019 06:24:25 -0800 +Subject: [PATCH] Small stylistic fixes + +--- + elftools/dwarf/namelut.py | 28 ++++++++++++++-------------- + 1 file changed, 14 insertions(+), 14 deletions(-) + +diff --git a/elftools/dwarf/namelut.py b/elftools/dwarf/namelut.py +index d24a5de..2cc32d4 100755 +--- a/elftools/dwarf/namelut.py ++++ b/elftools/dwarf/namelut.py +@@ -17,7 +17,7 @@ from ..construct import CString, Struct, If + NameLUTEntry = collections.namedtuple('NameLUTEntry', 'cu_ofs die_ofs') + + class NameLUT(collections.Mapping): +- """ ++ """ + A "Name LUT" holds any of the tables specified by .debug_pubtypes or + .debug_pubnames sections. This is basically a dictionary where the key is + the symbol name (either a public variable, function or a type), and the +@@ -48,10 +48,10 @@ class NameLUT(collections.Mapping): + + # iterate over items on a per-CU basis. + import itertools +- for cu_ofs, item_list in itertools.groupby(pubnames.items(), ++ for cu_ofs, item_list in itertools.groupby(pubnames.items(), + key = lambda x: x[1].cu_ofs): + # items are now grouped by cu_ofs. +- # item_list is an iterator yeilding NameLUTEntry'ies belonging ++ # item_list is an iterator yeilding NameLUTEntry'ies belonging + # to cu_ofs. + # We can parse the CU at cu_offset and use the parsed CU results + # to parse the pubname DIEs in the CU listed by item_list. +@@ -80,7 +80,7 @@ class NameLUT(collections.Mapping): + entries. The returned entries can be pickled to a file and restored by + calling set_entries on subsequent loads. + """ +- if self._entries is None: ++ if self._entries is None: + self._entries, self._cu_headers = self._get_entries() + return self._entries + +@@ -89,7 +89,7 @@ class NameLUT(collections.Mapping): + Set the NameLUT entries from an external source. The input is a + dictionary with the symbol name as the key and NameLUTEntry(cu_ofs, + die_ofs) as the value. +- ++ + This option is useful when dealing with very large ELF files with + millions of entries. The entries can be parsed once and pickled to a + file and can be restored via this function on subsequent loads. +@@ -101,7 +101,7 @@ class NameLUT(collections.Mapping): + """ + Returns the number of entries in the NameLUT. + """ +- if self._entries is None: ++ if self._entries is None: + self._entries, self._cu_headers = self._get_entries() + return len(self._entries) + +@@ -110,7 +110,7 @@ class NameLUT(collections.Mapping): + Returns a namedtuple - NameLUTEntry(cu_ofs, die_ofs) - that corresponds + to the given symbol name. + """ +- if self._entries is None: ++ if self._entries is None: + self._entries, self._cu_headers = self._get_entries() + return self._entries.get(name) + +@@ -118,7 +118,7 @@ class NameLUT(collections.Mapping): + """ + Returns an iterator to the NameLUT dictionary. + """ +- if self._entries is None: ++ if self._entries is None: + self._entries, self._cu_headers = self._get_entries() + return iter(self._entries) + +@@ -126,7 +126,7 @@ class NameLUT(collections.Mapping): + """ + Returns the NameLUT dictionary items. + """ +- if self._entries is None: ++ if self._entries is None: + self._entries, self._cu_headers = self._get_entries() + return self._entries.items() + +@@ -135,7 +135,7 @@ class NameLUT(collections.Mapping): + Returns NameLUTEntry(cu_ofs, die_ofs) for the provided symbol name or + None if the symbol does not exist in the corresponding section. + """ +- if self._entries is None: ++ if self._entries is None: + self._entries, self._cu_headers = self._get_entries() + return self._entries.get(name, default) + +@@ -143,9 +143,9 @@ class NameLUT(collections.Mapping): + """ + Returns all CU headers. Mainly required for readelf. + """ +- if self._cu_headers is None: ++ if self._cu_headers is None: + self._entries, self._cu_headers = self._get_entries() +- ++ + return self._cu_headers + + def _get_entries(self): +@@ -164,7 +164,7 @@ class NameLUT(collections.Mapping): + # So, field "name" is conditional. + entry_struct = Struct("Dwarf_offset_name_pair", + self._structs.Dwarf_offset('die_ofs'), +- If(lambda ctx: ctx['die_ofs'],CString('name'))) ++ If(lambda ctx: ctx['die_ofs'], CString('name'))) + + # each run of this loop will fetch one CU worth of entries. + while offset < self._size: +@@ -185,7 +185,7 @@ class NameLUT(collections.Mapping): + while True: + entry = struct_parse(entry_struct, self._stream) + +- # if it is zero, then we done. ++ # if it is zero, this is the terminating record. + if entry.die_ofs == 0: + break + # add this entry to the look-up dictionary. +-- +2.42.0.windows.2 + diff --git a/pyelftools.spec b/pyelftools.spec index 1c6a733..02075c4 100644 --- a/pyelftools.spec +++ b/pyelftools.spec @@ -9,7 +9,7 @@ Source0: https://files.pythonhosted.org/packages/source/p/pyelftools/pyel BuildRequires: python3-devel python3-setuptools BuildArch: noarch -Patch0001: 0001-Call-relocation-for-ARM-V3-194.patch +Patch0001: 0001-Small-stylistic-fixes.patch %description This package provides a python library for parsing and @@ -46,8 +46,8 @@ mv %{buildroot}/usr/bin/readelf.py %{buildroot}/usr/bin/pyreadelf %changelog -* Thu Dec 21 2023 liubo - 0.25-4 -- PYTHON-1918 Stop using BSON.encode and BSON.decode functions +* Tue Dec 26 2023 liubo - 0.25-4 +- Small stylistic fixes * Mon Nov 16 2020 baizhonggui - 0.25-3 - Drop Python 2 subpackage -- Gitee