OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package elf implements access to ELF object files. | 5 // Package elf implements access to ELF object files. |
6 package elf | 6 package elf |
7 | 7 |
8 import ( | 8 import ( |
9 "bytes" | 9 "bytes" |
10 "debug/dwarf" | 10 "debug/dwarf" |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 } | 719 } |
720 n := &f.gnuNeed[j] | 720 n := &f.gnuNeed[j] |
721 sym.Library = n.File | 721 sym.Library = n.File |
722 sym.Version = n.Name | 722 sym.Version = n.Name |
723 } | 723 } |
724 | 724 |
725 // ImportedLibraries returns the names of all libraries | 725 // ImportedLibraries returns the names of all libraries |
726 // referred to by the binary f that are expected to be | 726 // referred to by the binary f that are expected to be |
727 // linked with the binary at dynamic link time. | 727 // linked with the binary at dynamic link time. |
728 func (f *File) ImportedLibraries() ([]string, error) { | 728 func (f *File) ImportedLibraries() ([]string, error) { |
| 729 return f.DynString(DT_NEEDED) |
| 730 } |
| 731 |
| 732 // DynString returns the strings listed for the given tag in the file's dynamic |
| 733 // section. |
| 734 // |
| 735 // The tag must be one that takes string values: DT_NEEDED, DT_SONAME, DT_RPATH,
or |
| 736 // DT_RUNPATH. |
| 737 func (f *File) DynString(tag DynTag) ([]string, error) { |
| 738 switch tag { |
| 739 case DT_NEEDED, DT_SONAME, DT_RPATH, DT_RUNPATH: |
| 740 default: |
| 741 return nil, fmt.Errorf("non-string-valued tag %v", tag) |
| 742 } |
729 ds := f.SectionByType(SHT_DYNAMIC) | 743 ds := f.SectionByType(SHT_DYNAMIC) |
730 if ds == nil { | 744 if ds == nil { |
731 // not dynamic, so no libraries | 745 // not dynamic, so no libraries |
732 return nil, nil | 746 return nil, nil |
733 } | 747 } |
734 d, err := ds.Data() | 748 d, err := ds.Data() |
735 if err != nil { | 749 if err != nil { |
736 return nil, err | 750 return nil, err |
737 } | 751 } |
738 str, err := f.stringTable(ds.Link) | 752 str, err := f.stringTable(ds.Link) |
739 if err != nil { | 753 if err != nil { |
740 return nil, err | 754 return nil, err |
741 } | 755 } |
742 var all []string | 756 var all []string |
743 for len(d) > 0 { | 757 for len(d) > 0 { |
744 » » var tag DynTag | 758 » » var t DynTag |
745 » » var value uint64 | 759 » » var v uint64 |
746 switch f.Class { | 760 switch f.Class { |
747 case ELFCLASS32: | 761 case ELFCLASS32: |
748 » » » tag = DynTag(f.ByteOrder.Uint32(d[0:4])) | 762 » » » t = DynTag(f.ByteOrder.Uint32(d[0:4])) |
749 » » » value = uint64(f.ByteOrder.Uint32(d[4:8])) | 763 » » » v = uint64(f.ByteOrder.Uint32(d[4:8])) |
750 d = d[8:] | 764 d = d[8:] |
751 case ELFCLASS64: | 765 case ELFCLASS64: |
752 » » » tag = DynTag(f.ByteOrder.Uint64(d[0:8])) | 766 » » » t = DynTag(f.ByteOrder.Uint64(d[0:8])) |
753 » » » value = f.ByteOrder.Uint64(d[8:16]) | 767 » » » v = f.ByteOrder.Uint64(d[8:16]) |
754 d = d[16:] | 768 d = d[16:] |
755 } | 769 } |
756 » » if tag == DT_NEEDED { | 770 » » if t == tag { |
757 » » » s, ok := getString(str, int(value)) | 771 » » » s, ok := getString(str, int(v)) |
758 if ok { | 772 if ok { |
759 all = append(all, s) | 773 all = append(all, s) |
760 } | 774 } |
761 } | 775 } |
762 } | 776 } |
763 | |
764 return all, nil | 777 return all, nil |
765 } | 778 } |
OLD | NEW |