1
2
3
4 package joeq.Linker.ELF;
5
6 import java.io.IOException;
7 import jwutil.util.Assert;
8
9 /***
10 *
11 * @author John Whaley <jwhaley@alum.mit.edu>
12 * @version $Id: SymbolTableEntry.java 1941 2004-09-30 03:37:06Z joewhaley $
13 */
14 public class SymbolTableEntry implements ELFConstants {
15
16 protected int index;
17 protected String name;
18 protected int value;
19 protected int size;
20 protected byte info;
21 protected Section section;
22
23 public SymbolTableEntry(String name, int value, int size, byte bind, byte type, Section section) {
24 this.name = name; this.value = value; this.size = size; this.info = (byte)((bind<<4) | type); this.section = section;
25 }
26
27 public final String getName() { return name; }
28 public final int getValue() { return value; }
29 public final int getSize() { return size; }
30 public final byte getBind() { return (byte)(info>>4); }
31 public final byte getType() { return (byte)(info&0xf); }
32 public final byte getInfo() { return info; }
33 public final byte getOther() { return 0; }
34 public final int getSHndx() { return section.getIndex(); }
35
36 public void setIndex(int index) { Assert._assert(index != 0); this.index = index; }
37 public int getIndex() { Assert._assert(this.index != 0); return this.index; }
38
39 public void write(ELF file, Section.StrTabSection sts) throws IOException {
40 file.write_word(sts.getStringIndex(getName()));
41 file.write_addr(getValue());
42 file.write_word(getSize());
43 file.write_byte((byte)getInfo());
44 file.write_byte((byte)getOther());
45 file.write_half(getSHndx());
46 }
47
48 public static SymbolTableEntry read(ELF file, Section.StrTabSection sts) throws IOException {
49 int symbolname = file.read_word();
50 int value = file.read_addr();
51 int size = file.read_word();
52 byte info = file.read_byte();
53 byte other = file.read_byte();
54 int shndx = file.read_half();
55 String name;
56 if (symbolname != 0) {
57 name = sts.getString(symbolname);
58 } else {
59 name = "";
60 }
61 Section s = file.getSection(shndx);
62 return new SymbolTableEntry(name, value, size, (byte)((info >> 4) & 0xF), (byte)(info & 0xF), s);
63 }
64
65 public static class EmptySymbolTableEntry extends SymbolTableEntry {
66 private EmptySymbolTableEntry() { super("", 0, 0, STB_LOCAL, STT_NOTYPE, Section.NullSection.INSTANCE); }
67 public final int getIndex() { return 0; }
68 public final void setIndex(int index) { Assert._assert(index == 0); }
69 public static final EmptySymbolTableEntry INSTANCE = new EmptySymbolTableEntry();
70 }
71
72 public static int getEntrySize() { return 16; }
73 }