OLD | NEW |
1 | 1 |
2 # Modifies ld.so's ELF Program Headers to get a version that NaCl's | 2 # Modifies ld.so's ELF Program Headers to get a version that NaCl's |
3 # sel_ldr will run. | 3 # sel_ldr will run. |
4 # | 4 # |
5 # For a discussion, see: | 5 # For a discussion, see: |
6 # http://code.google.com/p/nativeclient/issues/detail?id=156 | 6 # http://code.google.com/p/nativeclient/issues/detail?id=156 |
7 # http://code.google.com/p/nativeclient/issues/detail?id=558 | 7 # http://code.google.com/p/nativeclient/issues/detail?id=558 |
8 | 8 |
9 import struct | 9 import struct |
10 import sys | 10 import sys |
(...skipping 25 matching lines...) Expand all Loading... |
36 raise AssertionError("Expected %s, got %s" % (expected, got)) | 36 raise AssertionError("Expected %s, got %s" % (expected, got)) |
37 | 37 |
38 def replace(ty, offset, value): | 38 def replace(ty, offset, value): |
39 fh.seek(offset) | 39 fh.seek(offset) |
40 fh.write(struct.pack(ty, value)) | 40 fh.write(struct.pack(ty, value)) |
41 | 41 |
42 # sel_ldr only accepts ELF objects with e_type=ET_EXEC. | 42 # sel_ldr only accepts ELF objects with e_type=ET_EXEC. |
43 check("B", offset_e_type, ET_DYN) | 43 check("B", offset_e_type, ET_DYN) |
44 replace("B", offset_e_type, ET_EXEC) | 44 replace("B", offset_e_type, ET_EXEC) |
45 | 45 |
46 # sel_ldr rejects ELF Program Headers other than PT_LOAD. | |
47 # Drop PT_DYNAMIC, PT_GNU_STACK and PT_TLS. | |
48 fh.seek(offset_ei_class) | |
49 elfclass = fh.read(1) | |
50 if elfclass == elfclass32: | |
51 check("H", offset_e_phnum32, 7) | |
52 replace("H", offset_e_phnum32, 3) | |
53 elif elfclass == elfclass64: | |
54 check("H", offset_e_phnum64, 7) | |
55 replace("H", offset_e_phnum64, 3) | |
56 else: | |
57 raise AssertionError("Unknown ELF class in file %s." % filename) | |
58 | |
59 fh.close() | 46 fh.close() |
60 | 47 |
61 | 48 |
62 if __name__ == "__main__": | 49 if __name__ == "__main__": |
63 main(sys.argv[1:]) | 50 main(sys.argv[1:]) |
OLD | NEW |