Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create global variable from DWARF #3985

Merged
merged 5 commits into from
Nov 19, 2023
Merged

Create global variable from DWARF #3985

merged 5 commits into from
Nov 19, 2023

Conversation

imbillow
Copy link
Contributor

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've documented or updated the documentation of every function and struct this PR changes. If not so I've explained why.
  • I've added tests that prove my fix is effective or that my feature works (if possible)
  • I've updated the rizin book with the relevant information (if needed)

Detailed description

...

Test plan

...

Closing issues

closes #3984

Copy link
Member

@XVilka XVilka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better now, thanks!
Please also add a test with a static variable defined inside a function with two cases:

int fn1(int a; int b) {
     static char* bla = NULL;
     ....
     bla = strdup("qwe");
 }
 
 int fn2(void *q, bool arg) {
      const static float qwe = 30.0;
      ....
      printf("qwe = %x\n", qwe);
}

Or something like that - with static inside the function, and const static too.

See also those 4 failed tests:


[XX] db/abi/compilers/gcc_64 ELF_ABI : gcc O0 dwarf info
RZ_NOPLUGINS=1 /usr/bin/rizin -escr.utf8=0 -escr.color=0 -escr.interactive=0 -eflirt.sigdb.load.system=false -eflirt.sigdb.load.home=false -N -Qc 'id~?
' bins/abi_bins/elf/compilers/gcc/echo_gcc_O0
-- stdout
--- expected
+++ actual
@@ -1,1 +1,1 @@
-25945
+25948

[**]                            db/abi/compilers/gcc_64    13735 OK       904 BR        1 XX       22 FX


[XX] db/abi/compilers/clang ELF_ABI : Clang m32 O0 dwarf info
RZ_NOPLUGINS=1 /usr/bin/rizin -escr.utf8=0 -escr.color=0 -escr.interactive=0 -eflirt.sigdb.load.system=false -eflirt.sigdb.load.home=false -N -Qc 'id~?
' bins/abi_bins/elf/compilers/clang/echo_clang_m32_O0
-- stdout
--- expected
+++ actual
@@ -1,1 +1,1 @@
-22327
+22330

-- stderr
ERROR: Global variable quoting_style_args at 0x804e2b4 already exists!

[**]                             db/abi/compilers/clang    13744 OK       904 BR        2 XX       22 FX


[XX] db/abi/compilers/clang_64 ELF_ABI : Clang O0 dwarf info
RZ_NOPLUGINS=1 /usr/bin/rizin -escr.utf8=0 -escr.color=0 -escr.interactive=0 -eflirt.sigdb.load.system=false -eflirt.sigdb.load.home=false -N -Qc 'id~?
' bins/abi_bins/elf/compilers/clang/echo_clang_O0
-- stdout
--- expected
+++ actual
@@ -1,1 +1,1 @@
-22442
+22445

[**]                          db/abi/compilers/clang_64    13753 OK       904 BR        3 XX       22 FX


[XX] db/abi/compilers/gcc ELF_ABI : gcc m32 O0 dwarf info
RZ_NOPLUGINS=1 /usr/bin/rizin -escr.utf8=0 -escr.color=0 -escr.interactive=0 -eflirt.sigdb.load.system=false -eflirt.sigdb.load.home=false -N -Qc 'id~?
' bins/abi_bins/elf/compilers/gcc/echo_gcc_m32_O0
-- stdout
--- expected
+++ actual
@@ -1,1 +1,1 @@
-25788
+25791

And (maybe unnecessary) error message:

[XX] db/rzil/ppc64 emulateme-little-endian
RZ_NOPLUGINS=1 /usr/bin/rizin -escr.utf8=0 -escr.color=0 -escr.interactive=0 -eflirt.sigdb.load.system=false -eflirt.sigdb.load.home=false -N -T -Qc 's sym.decrypt
e bin.str.enc=utf8
ps @ obj.seckrit
aezi
o malloc://0x1000 0x400000
o malloc://0x10 0x500000
e io.cache=1
w AnyColourYouLike @ 0x500000
ar r1=0x400000
ar r3=0x500000
aezsu 0x001007f8
ps @ obj.seckrit
' bins/elf/ppc/emulateme-ppc64le
-- stderr
--- expected
+++ actual
@@ -1,3 +1,32 @@
+ERROR: Global variable lock at 0x1e29f8 already exists!
+ERROR: Global variable lock at 0x1e29f8 already exists!
+ERROR: Global variable step4_jumps at 0x194f40 already exists!
+ERROR: Global variable state at 0x1e7010 already exists!
+ERROR: Global variable state at 0x1e7010 already exists!
+ERROR: Global variable __elf_set___libc_subfreeres_element_free_mem__ at 0x1af8f8 already exists!
+ERROR: Global variable __elf_set___libc_subfreeres_element_free_mem__ at 0x1af8f8 already exists!
+ERROR: Global variable map at 0x1e7788 already exists!

If we can't avoid it - should be only a warning at most.

@imbillow imbillow force-pushed the dwarf-global-variable branch 2 times, most recently from 753e458 to 7980e8e Compare November 18, 2023 18:04
@imbillow imbillow force-pushed the dwarf-global-variable branch from f46bfd8 to 8f9f3d6 Compare November 18, 2023 22:27
@wargio
Copy link
Member

wargio commented Nov 19, 2023

i think those "dup" should be INFO

@XVilka
Copy link
Member

XVilka commented Nov 19, 2023

@imbillow it affects loading the PE with debug symbols into Windows debugger:

[**]          C:\projects\rizin\test\db\analysis\xtensa    17016 OK       995 BR        0 XX       34 FX
[XX] C:\projects\rizin\test\db\archos\windows-x64\dbg_oo ood and doc
ANSICON=1 RZ_NOPLUGINS=1 C:\projects\rizin\rizin-clang_cl_64_dyn-v0.7.0\bin\rizin.exe -escr.utf8=0 -escr.color=0 -escr.interactive=0 -eflirt.sigdb.load.system=false -eflirt.sigdb.load.home=false -N -Qc '(reopen; ood > $_; doc > $_)
4 .(reopen)
' bins\pe\hello_world_not_stripped.exe
-- stderr
Spawned new process with pid 3328, tid = 3868
-- exit status: -1073741819
[**] C:\projects\rizin\test\db\archos\windows-x64\dbg_oo    17016 OK       995 BR        1 XX       34 FX

@XVilka XVilka merged commit 947e9b5 into dev Nov 19, 2023
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Global and static variables aren't created from DWARF
3 participants