[llvm] r355468 - [BinaryFormat] Add DT_USED tag into dynamic section.

Xing GUO via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 5 17:28:40 PST 2019


Author: higuoxing
Date: Tue Mar  5 17:28:40 2019
New Revision: 355468

URL: http://llvm.org/viewvc/llvm-project?rev=355468&view=rev
Log:
[BinaryFormat] Add DT_USED tag into dynamic section.

Summary:
This tag is documented in https://docs.oracle.com/cd/E19253-01/817-1984/chapter6-42444/index.html 
Though I could not find some docs that describe it in detail, I found some code snippets.

1.
```
	/*
	 * Look up the string in the string table and get its offset. If
	 * this succeeds, then it is possible that there is a DT_NEEDED
	 * dynamic entry that references it.
	 */
	have_string = elfedit_sec_findstr(argstate->str.sec,
	    strpad_elt.dn_dyn.d_un.d_val, arg, &str_offset) != 0;
	if (have_string) {
		dyn = argstate->dynamic.data;
		for (ndx = 0; ndx < numdyn; dyn++, ndx++) {
			if (((dyn->d_tag == DT_NEEDED) ||
			    (dyn->d_tag == DT_USED)) &&
			    (dyn->d_un.d_val == str_offset))
				goto done;
		}
	}
```
https://github.com/kofemann/opensolaris/blob/80192cd83bf665e708269dae856f9145f7190f74/usr/src/cmd/sgs/elfedit/modules/common/syminfo.c#L512

2.
```
    case DT_USED:
    case DT_INIT_ARRAY:
    case DT_FINI_ARRAY:
      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);
              break;
            }
        }

          print_vma (entry->d_un.d_val, PREFIX_HEX);
          putchar ('\n');
        }
      break;
```
http://web.mit.edu/freebsd/head/contrib/binutils/binutils/readelf.c

3.
```
#define DT_USED     0x7ffffffe  /* ignored - same as needed */
```
https://github.com/switchbrew/switch-tools/blob/master/src/elf_common.h

Reviewers: jhenderson, grimar

Reviewed By: jhenderson, grimar

Subscribers: emaste, krytarowski, fedor.sergeev, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D58762

Modified:
    llvm/trunk/include/llvm/BinaryFormat/DynamicTags.def
    llvm/trunk/test/tools/obj2yaml/dynamic-section.test

Modified: llvm/trunk/include/llvm/BinaryFormat/DynamicTags.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/DynamicTags.def?rev=355468&r1=355467&r2=355468&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BinaryFormat/DynamicTags.def (original)
+++ llvm/trunk/include/llvm/BinaryFormat/DynamicTags.def Tue Mar  5 17:28:40 2019
@@ -196,6 +196,7 @@ PPC64_DYNAMIC_TAG(PPC64_GLINK, 0x7000000
 
 // Sun machine-independent extensions.
 DYNAMIC_TAG(AUXILIARY, 0x7FFFFFFD) // Shared object to load before self
+DYNAMIC_TAG(USED, 0x7FFFFFFE)      // Same as DT_NEEDED
 DYNAMIC_TAG(FILTER, 0x7FFFFFFF)    // Shared object to get values from
 
 

Modified: llvm/trunk/test/tools/obj2yaml/dynamic-section.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/obj2yaml/dynamic-section.test?rev=355468&r1=355467&r2=355468&view=diff
==============================================================================
--- llvm/trunk/test/tools/obj2yaml/dynamic-section.test (original)
+++ llvm/trunk/test/tools/obj2yaml/dynamic-section.test Tue Mar  5 17:28:40 2019
@@ -122,6 +122,8 @@
 # CHECK-NEXT:        Value:           0x0000000000000035
 # CHECK-NEXT:      - Tag:             DT_VERNEEDNUM
 # CHECK-NEXT:        Value:           0x0000000000000036
+# CHECK-NEXT:      - Tag:             DT_USED
+# CHECK-NEXT:        Value:           0x0000000000000001
 
 !ELF
 FileHeader:
@@ -246,3 +248,5 @@ Sections:
         Value:           0x0000000000000035
       - Tag:             DT_VERNEEDNUM
         Value:           0x0000000000000036
+      - Tag:             DT_USED
+        Value:           0x0000000000000001




More information about the llvm-commits mailing list