[Toybox] [PATCH] readelf: Fix the section flags handling.

Rob Landley rob at landley.net
Fri Dec 1 22:00:22 PST 2023


On 12/1/23 16:20, enh wrote:
> On Fri, Dec 1, 2023 at 2:06 PM Rob Landley <rob at landley.net> wrote:
>>
>> On 12/1/23 09:41, enh wrote:
>> >> Does it have any sort of stat -c syntax where I can at least REQUEST what I want
>> >> out of it? No it does not. Because gnu. (Don't suggest it to them, they'll fsck
>> >> it up 100% guaranteed.)
>> >
>> > (i don't really use the gnu one any more anyway. there's an
>> > llvm-readelf too, and -- like all the other llvm tools -- it "just
>> > works" regardless of what architecture the ELF file is for. it's worth
>> > switching for that alone. and they _do_ have a proper machine-readable
>> > format if you ask for it.)
>>
>> How do I ask?
> 
> `--elf-output-style=` and GNU, LLVM, or JSON (annoyingly all in
> caps!). there's also llvm-readobj which defaults to json.

Ah. Json. That explains why I hadn't heard of this being useful to anyone before.

Let's see what the LLVM one...

$
/home/android/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-readelf
-SW tests/files/elf/ndk-elf-note-full --elf-output-style=LLVM
...
  Section {
    Index: 31
    Name: .strtab (9)
    Type: SHT_STRTAB (0x3)
    Flags [ (0x0)
    ]
    Address: 0x0
    Offset: 0x1B18
    Size: 500
    Link: 0
    Info: 0
    AddressAlignment: 1
    EntrySize: 0
  }

Nope, even less friendly to something like shell pipelines. (I think that's just
the json with indentation and newlines instead of quotes and commas? It's not
even a consistent format, the Flags field isn't a name: value entry on one line.)

Needing to pull in a library to parse the data (or use something like python)
isn't really maintaining the ideals of unix either. Oh well.

Lemme throw this on the TODO heap and get back to it...

Rob


More information about the Toybox mailing list