Page MenuHomePhabricator

[llvm-readobj]Add additional testing for various ELF features

Authored by jhenderson on Feb 26 2019, 7:52 AM.



This patch adds testing of areas of the code that are not fully tested, in particular dynamic table printing, ELF type printing, handling of edge cases where things are missing/empty (relocations/program header tables/section header table), and the --string-dump switch.

Diff Detail


Event Timeline

jhenderson created this revision.Feb 26 2019, 7:52 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: srhines. · View Herald Transcript
Higuoxing added inline comments.Feb 26 2019, 8:25 PM
16–17 ↗(On Diff #188378)

Here should be

# RUN: %python -c "with open(r'%t.truncated1', 'r+') as f: f.truncate(0x1001)"
# RUN: not llvm-readobj %t.truncated1 --dynamic-table 2>&1 | FileCheck %s


22 ↗(On Diff #188378)

Here should be

# RUN: %python -c "with open(r'%t.truncated2', 'r+') as f: f.truncate(0x1001)"
# RUN: not llvm-readobj %t.truncated2 --dynamic-table 2>&1 | FileCheck %s
rupprecht accepted this revision.Feb 26 2019, 9:40 PM

I always like having more tests :D

1 ↗(On Diff #188378)

nit: it seems like uppercase filenames are rarely used, "elf-dynamic-no-pt-dynamic.test" might be better
Same with the other pt_dynamic test

This revision is now accepted and ready to land.Feb 26 2019, 9:40 PM
MaskRay added inline comments.
213 ↗(On Diff #188378)

0x1f to enumerate all DF_* flags?

251 ↗(On Diff #188378)

Use 0x03ffffff to enumerate all DF_1_* flags?

grimar added inline comments.Feb 27 2019, 2:05 AM
92 ↗(On Diff #188378)

Do I correctly understand that issue here is that DT_NEEDED has a value 0x1, which
is an offset in a .dynstr, and the issue is that DT_STRSZ says that .dynstr has a total size of 1
(and so offset 0x1 is past the end of the section)?

If so, it is not really obvious perhaps, I would suggest extending the comment for this sub-test.

275 ↗(On Diff #188378)

Could you explain the logic of numeric tags for me?

I see you're testing LOPROC and (HIPROC-1) it seems:

DYNAMIC_TAG_MARKER(LOOS, 0x60000000) Start of environment specific tags.
End of environment specific tags.
DYNAMIC_TAG_MARKER(LOPROC, 0x70000000) Start of processor specific tags.
End of processor specific tags.

But what is 0x6000000D and 0x6ffff000 then?

Higuoxing added inline comments.Feb 27 2019, 3:45 AM
150 ↗(On Diff #188378)

I think here should be linked with .dynstr

- Name: .dynamic
  Link: 1

Or, objdump cannot dump this. But, never mind here :)

jhenderson marked 5 inline comments as done.Feb 27 2019, 4:04 AM
jhenderson added inline comments.
92 ↗(On Diff #188378)

Yes, that's correct. I'll improve it.

213 ↗(On Diff #188378)

I'll go the whole hog and do 0xffffffffffffffff, to enumerate all flags current and future.

251 ↗(On Diff #188378)


275 ↗(On Diff #188378)

I can't remember my own logic now!

I'm interested in other reserved values effectively, that don't have a known meaning in LLVM, but looking at the known values, I don't see any reason to not use 0x60000000. Note that 0x6FFFFFFF is DT_VERNEEDNUM, so I can't use that. The highest I can use is 0x6FFFFFF8, I believe. I could also test a mid-range value too, if that's desirable?

By the way, I'm using 0x7ffffffe, because 0x7fffffff is DT_FILTER.

16–17 ↗(On Diff #188378)

Oops, thanks. I'll fix that. I renamed the file, so there must be one still in my test output directory of the old name.

grimar added inline comments.Feb 27 2019, 4:22 AM
275 ↗(On Diff #188378)

Not sure about 0x7ffffffe, because it is surrounded by DT_AUXILIARY(0x7FFFFFFD) and DT_FILTER(0x7FFFFFFF),
I guess someone might want to use it one day.

Seems to test that we can work with unknown tags you can just test a single value and perhaps any
obviously unused/weird value like 0x6ABCDEF0 would work here?

Higuoxing added inline comments.Feb 27 2019, 4:39 AM
275 ↗(On Diff #188378)

0x7ffffffe is DT_USED
I find some code example, but cannot find docs on it.

#define	DT_USED		0x7ffffffe	/* ignored - same as needed */


	case DT_USED:
	  if (do_dynamic)
	      if (entry->d_tag == DT_USED
		  && VALID_DYNAMIC_NAME (entry->d_un.d_val))
		  char *name = GET_DYNAMIC_NAME (entry->d_un.d_val);

		  if (*name)
		      printf (_("Not needed object: [%s]\n"), name);

	      print_vma (entry->d_un.d_val, PREFIX_HEX);
	      putchar ('\n');

jhenderson marked 10 inline comments as done.

Address review comments:

  1. Rename tests to lower case.
  2. Fix test file names.
  3. Change tags in reserved range to be more sensible.
  4. Use all values in DT_FLAGS and DT_FLAGS_1 tags.
  5. Add a couple of comments for clarity.
grimar accepted this revision.Feb 27 2019, 8:02 AM


Higuoxing accepted this revision.Feb 27 2019, 8:18 AM
jhenderson added inline comments.Feb 27 2019, 8:33 AM
150 ↗(On Diff #188378)

I'm trying to keep these tests as minimal as possible, because there's already a lot of stuff in it. llvm-readobj does not require the link field, because it uses the dynamic tags.

This revision was automatically updated to reflect the committed changes.