Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
bash script: pipe to nm issue [won't fix]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
CaptainBlood
Veteran
Veteran


Joined: 24 Jan 2010
Posts: 1442

PostPosted: Sat Feb 29, 2020 8:34 pm    Post subject: bash script: pipe to nm issue [won't fix] Reply with quote

Bash script needs to extract symbols from kernel modules.
nm is the right tool to do it.
Except it doesn't allow piped decompressed module, i.e.:
Code:
unxz -c /lib/modules/5.4.22-gentoo-rt/block/vhba.ko.xz | nm
nm: 'a.out': No such file
Any neat idea to fix this?
Thks 4 ur attention, interest & support.


Last edited by CaptainBlood on Sat Feb 29, 2020 9:55 pm; edited 2 times in total
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14957

PostPosted: Sat Feb 29, 2020 9:23 pm    Post subject: Reply with quote

stream-file | nm /proc/self/fd/0
Back to top
View user's profile Send private message
Ionen
Guru
Guru


Joined: 06 Dec 2018
Posts: 538

PostPosted: Sat Feb 29, 2020 9:26 pm    Post subject: Reply with quote

^ unfortunately doesn't work (or at least not on my end), nm complains that it's not a normal file. It works if doing nm /dev/stdin < test.ko, but not with a pipe for some reason.

May be required to use a temporary file here.


Last edited by Ionen on Sat Feb 29, 2020 9:34 pm; edited 2 times in total
Back to top
View user's profile Send private message
CaptainBlood
Veteran
Veteran


Joined: 24 Jan 2010
Posts: 1442

PostPosted: Sat Feb 29, 2020 9:28 pm    Post subject: Reply with quote

Code:
unxz -c /lib/modules/5.4.22-gentoo-rt/block/vhba.ko.xz | nm /proc/self/fd/0
nm: Warning: '/proc/self/fd/0' is not an ordinary file
Thks 4 ur attention, interest & support
Back to top
View user's profile Send private message
CaptainBlood
Veteran
Veteran


Joined: 24 Jan 2010
Posts: 1442

PostPosted: Sat Feb 29, 2020 9:33 pm    Post subject: Reply with quote

Ionen wrote:
May be required to use a temporary file here.
Yeah, I got it working that so dirty way :twisted:
a.out needs to be generated, a.out may already exist, needs to be deleted after use, etc... ugly binutils!
Thks 4 ur attention, interest & support.


Last edited by CaptainBlood on Sat Feb 29, 2020 9:42 pm; edited 1 time in total
Back to top
View user's profile Send private message
Ionen
Guru
Guru


Joined: 06 Dec 2018
Posts: 538

PostPosted: Sat Feb 29, 2020 9:40 pm    Post subject: Reply with quote

Well, it doesn't need to be a.out, you can "nm file.ko" which could be a random name made with mktemp or similar

I feel there may be a way to make this work with redirections anyway but not sure :?
Back to top
View user's profile Send private message
CaptainBlood
Veteran
Veteran


Joined: 24 Jan 2010
Posts: 1442

PostPosted: Sat Feb 29, 2020 9:49 pm    Post subject: Reply with quote

Ionen wrote:
mktemp or similar

No sure it would be easier as still would require to retrieve generated file name, i.e. one step more, at least.
Thks 4 ur attention, interest & support.
Back to top
View user's profile Send private message
CaptainBlood
Veteran
Veteran


Joined: 24 Jan 2010
Posts: 1442

PostPosted: Sat Feb 29, 2020 9:54 pm    Post subject: Reply with quote

Here binutils is likely to deserve a bug report.
Must say I feel lazy to do so.
Thks 4 ur attention, interest & support.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14957

PostPosted: Sun Mar 01, 2020 3:49 am    Post subject: Reply with quote

Ionen wrote:
^ unfortunately doesn't work (or at least not on my end), nm complains that it's not a normal file. It works if doing nm /dev/stdin < test.ko, but not with a pipe for some reason.
I tested with redirecting from a file, but didn't test with a pipe. Pipe does not work for me, either. Most likely, nm wants to seek within the stream, and that is not legal on pipes.

Although not exactly a redirection as intended, this could be done by writing the decompressed file to a deleted temporary file, then having nm reopen the temporary. It would be a regular file, but it would automatically vanish when the last descriptor to it was closed.
Back to top
View user's profile Send private message
CaptainBlood
Veteran
Veteran


Joined: 24 Jan 2010
Posts: 1442

PostPosted: Sun Mar 01, 2020 5:36 am    Post subject: Reply with quote

Hu wrote:
[Although not exactly a redirection as intended, this could be done by writing the decompressed file to a deleted temporary file, then having nm reopen the temporary. It would be a regular file, but it would automatically vanish when the last descriptor to it was closed.
Pipe aren't strictly required as such.
I cannot figure out how to create a file that would be automatically deleted as suggested.
Can you elaborate?
Thks 4 ur attention, interest & support.
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1849

PostPosted: Sun Mar 01, 2020 9:16 am    Post subject: Reply with quote

The easiest way possible: create a file, have nm open it and then delete that file (even though nm hasn't finished processing it yet)
You could also open that file yourself, delete it and pass a file descriptor instead.
Or try invoking it with a pipe as "nm /dev/stdin" without creating a temporary file, which is pretty much the same as "nm /proc/self/fd/0", but you can never be sure the results when your program acts in a weird way.
Back to top
View user's profile Send private message
CaptainBlood
Veteran
Veteran


Joined: 24 Jan 2010
Posts: 1442

PostPosted: Sun Mar 01, 2020 9:29 am    Post subject: Reply with quote

Anything shorter than:
Code:
unxz -c $1>a.out
nm
[[ -f a.out ]] && rm a.out
? (alternatively gunzip instead of unxz)
Thks 4 ur attention, interest & support
Back to top
View user's profile Send private message
guitou
Guru
Guru


Joined: 02 Oct 2003
Posts: 446
Location: France

PostPosted: Sun Mar 01, 2020 3:26 pm    Post subject: Reply with quote

Hello.
Looks like there is a --stdout to unxz. Did you try this?

++
Gi)
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14957

PostPosted: Sun Mar 01, 2020 5:41 pm    Post subject: Reply with quote

guitou wrote:
Looks like there is a --stdout to unxz. Did you try this?
Yes. --stdout is the long form of -c, which was used in the opening post.

CaptainBlood: the typical approach would be to mktemp, open the resulting file, then delete it, then run the child processes accordingly. For example (lightly tested):
Code:
#!/bin/bash

set -e
tmpfile="$(mktemp --tmpdir ko-nm.XXXXXXXX)"
exec {fd}<> "$tmpfile"
rm "$tmpfile"
unxz -c "$1" >/proc/self/fd/$fd
nm /proc/self/fd/$fd
Back to top
View user's profile Send private message
CaptainBlood
Veteran
Veteran


Joined: 24 Jan 2010
Posts: 1442

PostPosted: Sun Mar 01, 2020 7:38 pm    Post subject: Reply with quote

That's very interesting from a generic point of view.
I'll try that in a couple of hours.

Thks 4 ur attention, interest & support.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum