Skip to content

Conversation

@StudioEtrange
Copy link
Contributor

Add option to choose a backend tool.

In some case, we dont have scanelf binary, but readelf

So we can choose to change the default one (scanelf)

@StudioEtrange
Copy link
Contributor Author

example :

Use scanelf

./lddtree.sh $(which ps)
./lddtree.sh -b scanelf $(which ps)

Use readelf

./lddtree.sh -b readelf $(which ps)

@ncopa
Copy link
Owner

ncopa commented May 30, 2016

I am not against this, but I'd like to move every if [ "$BACKEND" = "scanelf" ]; then ... elif [ "$BACKED" = "readelf" ]; then ... fiinto wrapper functions. For example:

# readelf variants
do_something_readelf() {
    readelf --something $1 ....
}

foobar_readelf() {
   readelf --foobar $@ ....
}

# scanelf variants
do_something_scanelf() {
    scanelf --some-thing $1 ....
}

foobar_scanelf() {
    scanelf --foo-bar $@ ....
}

BACKEND=scanelf

# abstraction wrapper functions
do_something() {
    do_something_$BACKEND "$@"
}

foobar() {
   foobar_$BACKEND "$@"
}

And then we replace:

if [ "$BACKEND" = "scanelf" ]; then
    scanelf --some-thing ....
elif [ "$BACKEND" = "readelf" ]; then
    readelf --something ....
fi

with:

do_something ....

…er. Two fixes with ORIGIN in rpath and relative path of elf
@StudioEtrange
Copy link
Contributor Author

StudioEtrange commented May 31, 2016

Ok.

Then, I made wrapper functions.

And first I posted two fixes :

  • Use of g flag with sed when replace of $ORIGIN in RPATH. Because we may have several $ORIGIN in rpath

scanelf -qF '#F%r' "${_file}" | sed -e "s:[$]ORIGIN:${_file%/*}:g"

  • When we pass a relative elf path, RPATH wich contains $ORIGIN are turned into relative path and might not be resolved

[ -z "${path##/*}" ] || path="${PWD}/${path}"

stella>objdump -p tutu/libpng/1_6_17/lib/libpng.so | grep RUNPATH
RUNPATH $ORIGIN/../stella-dep:$ORIGIN/stella-dep

stella>./nix/pool/artefact/lddtree/lddtree.sh -b scanelf tutu/libpng/1_6_17/lib/libpng.so
libpng.so => tutu/libpng/1_6_17/lib/libpng.so (interpreter => none)
libz.so.1 => /stella/tutu/libpng/1_6_17/lib/../stella-dep/libz.so.1
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6
ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6`

And second I added two more options :

  • --no-header which do not print analysed elf and its interpreter
  • --no-recursive to not analyse dependencies of dependencies

And Last, I have a question

  • AUTO ROOT option seems to replace the root of elf path only if we use absolute path. Is it right ?

if ${AUTO_ROOT} && [ -z "${elf##/*}" ] ; then elf="${ROOT}${elf#/}"; fi

@ncopa
Copy link
Owner

ncopa commented Jun 1, 2016

can you please split the commit with wrapper function and new options and rebase?

@StudioEtrange
Copy link
Contributor Author

StudioEtrange commented Jun 1, 2016

Ok i will do a complete fresh pull request with 3 split commit...
one for fixes, one for backend, one for no-header/no-recursive

Is this ok for you ?

Or do you want, 3 distincts PR ?

@ncopa
Copy link
Owner

ncopa commented Jun 1, 2016

one pr and 3 commits sounds good 👍

but you dont need create new PR, i think you can git push --force and the commits in this PR will be updated.

@ncopa
Copy link
Owner

ncopa commented Jul 14, 2016

i pushed the feature in 2 logic steps:

  • refactor to use scanelf via wrapper
  • add binutils wrapper, and use this if scanelf is not found

Can you please verify that this works for you and the also provide the fixes in separate PR?

Thanks!

@ncopa ncopa closed this Jul 14, 2016
@StudioEtrange
Copy link
Contributor Author

StudioEtrange commented Jul 14, 2016

Oh man
I have just pushed all my modifications and fixes to my forked version to analyse the whole diffs.

There is a lot. And as I was so in a hurry and not so well organized, my commits groups several different topic. In a word : it's a kind of mess.

There is 4 new options : no recursive, no header, list only dependencies (-m), force a backend (-b)
Support for multiple rpath values (with /g on sed expressions)
And a few fixes I cant remember

Actually I have integrated my forked version into a bigger tools (https://github.com/StudioEtrange/stella) and I use lddtree with another script I made (https://github.com/StudioEtrange/stella/blob/master/nix/common/lib-parse-bin.sh)
to be able to analyse any kind of binary

But I will try my best, when I will have time, to push options and fixes upstream to your repo.

@ncopa
Copy link
Owner

ncopa commented Jul 14, 2016

@StudioEtrange And as I was so in a hurry and not so well organized, my commits groups several different topic. In a word : it's a kind of mess.

This is main reason I didn't merge it.

@StudioEtrange
Copy link
Contributor Author

I know...
Ok, everything done.
For now, I have posted 2 PR.
And I will have 2 more waiting in separate branches that i will create after you merge PR#1 and PR#2. If you wish.

Every PR have a limit number of commits and is dedicated to a specific topic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants