Page MenuHomeFreeBSD

Replace using of objdump with elfdump
ClosedPublic

Authored by lwhsu on Jan 6 2017, 10:10 AM.

Details

Summary

In-tree objdump is too old for dump new elf headers. But if we use
make CROSS_TOOLCHAIN= and not specify CROSS_BINUTILS_PREFIX in env,
embed_mfs.sh cannot find the correct objdump. This patch just replaces using
of objdump with elfdump to collect needed information.

Later we may also put an ELFDUMP in CROSSENV and use it in embed_mfs.sh .

Test Plan

Follow https://wiki.freebsd.org/riscv :

  • build a kernel with MFS embedded
  • build a BBL contains that kernel
  • boot BBL with qemu-system-riscv64

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

lwhsu retitled this revision from to Replace using of objdump with elfdump.
lwhsu updated this object.
lwhsu edited the test plan for this revision. (Show Details)
lwhsu added reviewers: emaste, br, bdrewery.
sys/tools/embed_mfs.sh
44 ↗(On Diff #23653)

so your delimeter is ' ' and you look for 10th element in the list ? It does not work for me

may be we can still use awk here? it should work and easier to read, for example:

sec_size=`echo ${sec_info} | grep sh_size | awk '{print $2}' 2> /dev/null`
sys/tools/embed_mfs.sh
44 ↗(On Diff #23653)

I don't like this, either. But I found that

sec_info=`elfdump -c $1 2> /dev/null | grep "oldmfs" -A 5`

just concatenates all lines into one line thus awk does not work here. I'll try to find a more elegant solution.

Oh, readelf -WS might be a suitable way as well - it outputs everything on one line and should be a straightforward change from the current objdump output parsing.

objdump -h:

0 .text         00111383  0000000000000000  0000000000000000  00000040  2**4
                CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE

readelf -WS:

[ 1] .text             PROGBITS        0000000000000000 000040 111383 00  AX  0   0 16

A caveat with readelf -WS I guess is that the section index is space-padded in [ ] (e.g. [ 1], [ 2], ..., [10] etc.) so the field numbers are not consistent, but we could handle that in a few different ways.

lwhsu edited edge metadata.

Oh, I found that what we need here is simply a pair of double quotes.

sys/tools/embed_mfs.sh
39 ↗(On Diff #23834)

I suspect you want at least the leading space, to avoid a possible false positive elsewhere? Also I think it's conventional to put the options before the grep string.

So perhaps grep -A 5 " oldmfs"?

43–44 ↗(On Diff #23834)

You can simplify the pipeline with something like awk '/sh_size/ {print $2}/

  • Use more specified grep pattern to avoid false positive
  • Move option right after grep command
  • Simplify pipeline with pure awk
lwhsu added inline comments.
sys/tools/embed_mfs.sh
39 ↗(On Diff #23834)

How about this: grep -A 5 "sh_name: oldmfs$" ?

emaste edited edge metadata.
This revision is now accepted and ready to land.Jan 10 2017, 5:10 PM
sys/tools/embed_mfs.sh
39 ↗(On Diff #23834)

I seem to have lost my comment, so adding again after accepting:

Much better. You might want an explicit egrep or grep -E for the $ though?

lwhsu edited edge metadata.

Explicitly state we're using extended regular expression.

This revision now requires review to proceed.Jan 10 2017, 5:42 PM
emaste edited edge metadata.
This revision is now accepted and ready to land.Jan 10 2017, 5:47 PM
br edited edge metadata.
This revision was automatically updated to reflect the committed changes.