diff --git a/crates/examples/testfiles/xcoff/base.o.objdump b/crates/examples/testfiles/xcoff/base.o.objdump index 99ece666..3e2a989a 100644 --- a/crates/examples/testfiles/xcoff/base.o.objdump +++ b/crates/examples/testfiles/xcoff/base.o.objdump @@ -11,12 +11,12 @@ Symbols 0: Symbol { name: ".file", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } 3: Symbol { name: ".printf", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: None } 5: Symbol { name: "printf", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: None } -7: Symbol { name: ".text", address: 0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +7: Symbol { name: ".text", address: 0, size: 57, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 9: Symbol { name: ".main", address: 0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -11: Symbol { name: ".rodata.str1.1L...str", address: 58, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -13: Symbol { name: "main", address: 68, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +11: Symbol { name: ".rodata.str1.1L...str", address: 58, size: d, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +13: Symbol { name: "main", address: 68, size: 18, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } 15: Symbol { name: "TOC", address: 80, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -17: Symbol { name: ".rodata.str1.1L...str", address: 80, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +17: Symbol { name: ".rodata.str1.1L...str", address: 80, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } .text relocations (1e, Relocation { kind: Got, encoding: Generic, size: 0, target: Symbol(SymbolIndex(11)), addend: 0, implicit_addend: true }) diff --git a/crates/examples/testfiles/xcoff/base.xcoff.objdump b/crates/examples/testfiles/xcoff/base.xcoff.objdump index 614012ff..3965d56b 100644 --- a/crates/examples/testfiles/xcoff/base.xcoff.objdump +++ b/crates/examples/testfiles/xcoff/base.xcoff.objdump @@ -21,73 +21,73 @@ Symbols 16: Symbol { name: "__crt0v", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: None } 18: Symbol { name: "__malloc_user_defined_name", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: None } 20: Symbol { name: "TOC", address: 1100008b8, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -22: Symbol { name: "__crt0v", address: 110000900, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -24: Symbol { name: "crt0_data", address: 110000908, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -26: Symbol { name: "__run_final_dtors", address: 110000910, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -28: Symbol { name: "_$STATIC", address: 110000918, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -30: Symbol { name: "__C_runtime_termination", address: 110000920, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -32: Symbol { name: "atexit", address: 110000928, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -34: Symbol { name: "_cdtors", address: 110000930, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -36: Symbol { name: "__run_initial_ctors", address: 110000938, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -38: Symbol { name: "exit", address: 110000940, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -40: Symbol { name: "__n_pthreads", address: 110000948, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -42: Symbol { name: "__mod_init", address: 110000950, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -44: Symbol { name: "__malloc_user_defined_name", address: 110000958, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -46: Symbol { name: "errno", address: 110000960, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -48: Symbol { name: ".rodata.str1.1L...str", address: 110000968, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -50: Symbol { name: "printf", address: 110000970, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +22: Symbol { name: "__crt0v", address: 110000900, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +24: Symbol { name: "crt0_data", address: 110000908, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +26: Symbol { name: "__run_final_dtors", address: 110000910, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +28: Symbol { name: "_$STATIC", address: 110000918, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +30: Symbol { name: "__C_runtime_termination", address: 110000920, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +32: Symbol { name: "atexit", address: 110000928, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +34: Symbol { name: "_cdtors", address: 110000930, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +36: Symbol { name: "__run_initial_ctors", address: 110000938, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +38: Symbol { name: "exit", address: 110000940, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +40: Symbol { name: "__n_pthreads", address: 110000948, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +42: Symbol { name: "__mod_init", address: 110000950, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +44: Symbol { name: "__malloc_user_defined_name", address: 110000958, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +46: Symbol { name: "errno", address: 110000960, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +48: Symbol { name: ".rodata.str1.1L...str", address: 110000968, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +50: Symbol { name: "printf", address: 110000970, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } 52: Symbol { name: "", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } 53: Symbol { name: "crt0_64.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -54: Symbol { name: ".__start", address: 1000001f8, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +54: Symbol { name: ".__start", address: 1000001f8, size: ad, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 56: Symbol { name: ".__start", address: 1000001f8, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -58: Symbol { name: "__start", address: 110000848, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -60: Symbol { name: "crt0_data", address: 1100006d0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -62: Symbol { name: "p_xargc", address: 1100008c0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -64: Symbol { name: "p_xargv", address: 1100008f0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -66: Symbol { name: "p_xrcfg", address: 1100008f8, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -68: Symbol { name: "p_xrc", address: 1100008fc, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -70: Symbol { name: "_malloc_user_defined_name", address: 1100008b8, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +58: Symbol { name: "__start", address: 110000848, size: 10, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +60: Symbol { name: "crt0_data", address: 1100006d0, size: 68, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +62: Symbol { name: "p_xargc", address: 1100008c0, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +64: Symbol { name: "p_xargv", address: 1100008f0, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +66: Symbol { name: "p_xrcfg", address: 1100008f8, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +68: Symbol { name: "p_xrc", address: 1100008fc, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +70: Symbol { name: "_malloc_user_defined_name", address: 1100008b8, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } 72: Symbol { name: ".file", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -76: Symbol { name: "", address: 1000002c0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +76: Symbol { name: "", address: 1000002c0, size: 160, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 78: Symbol { name: ".__threads_init", address: 1000002c0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 80: Symbol { name: ".__threads_init@AF2_1", address: 100000300, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -82: Symbol { name: "_$STATIC", address: 110000738, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -84: Symbol { name: "__threads_init", address: 110000858, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -86: Symbol { name: "__pth_init_routine", address: 1100008c8, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -88: Symbol { name: "_bsd_init_routine", address: 1100008d0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -90: Symbol { name: "_xti_tli_init_routine", address: 1100008d8, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -92: Symbol { name: "_nsl_init_routine", address: 1100008e0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -94: Symbol { name: "__dce_compat_init_routine", address: 1100008e8, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +82: Symbol { name: "_$STATIC", address: 110000738, size: 59, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +84: Symbol { name: "__threads_init", address: 110000858, size: 18, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +86: Symbol { name: "__pth_init_routine", address: 1100008c8, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +88: Symbol { name: "_bsd_init_routine", address: 1100008d0, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +90: Symbol { name: "_xti_tli_init_routine", address: 1100008d8, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +92: Symbol { name: "_nsl_init_routine", address: 1100008e0, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +94: Symbol { name: "__dce_compat_init_routine", address: 1100008e8, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } 96: Symbol { name: ".file", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -100: Symbol { name: "", address: 100000420, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +100: Symbol { name: "", address: 100000420, size: 178, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 102: Symbol { name: ".__User_sinit_begin", address: 100000420, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 104: Symbol { name: ".__C_runtime_termination", address: 100000448, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 106: Symbol { name: ".__C_runtime_startup", address: 100000498, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 108: Symbol { name: ".__dftdt__L304e50f8c42_5CatchFv", address: 100000520, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -110: Symbol { name: "_$STATIC", address: 1100007a0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -112: Symbol { name: "__dftdt__L304e50f8c42_5CatchFv", address: 110000888, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -114: Symbol { name: "__C_runtime_termination", address: 1100008a0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -116: Symbol { name: "__C_runtime_startup", address: 110000870, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -118: Symbol { name: "_cdtors", address: 110000838, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: true, flags: None } -120: Symbol { name: "__C_runtime_pstartup", address: 110000798, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +110: Symbol { name: "_$STATIC", address: 1100007a0, size: 95, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +112: Symbol { name: "__dftdt__L304e50f8c42_5CatchFv", address: 110000888, size: 18, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +114: Symbol { name: "__C_runtime_termination", address: 1100008a0, size: 18, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +116: Symbol { name: "__C_runtime_startup", address: 110000870, size: 18, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +118: Symbol { name: "_cdtors", address: 110000838, size: 10, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: true, flags: None } +120: Symbol { name: "__C_runtime_pstartup", address: 110000798, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } 122: Symbol { name: ".file", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -125: Symbol { name: ".text", address: 100000640, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +125: Symbol { name: ".text", address: 100000640, size: 57, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 127: Symbol { name: ".main", address: 100000640, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -129: Symbol { name: ".rodata.str1.1L...str", address: 1000006c0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +129: Symbol { name: ".rodata.str1.1L...str", address: 1000006c0, size: d, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 131: Symbol { name: "glink64.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -132: Symbol { name: ".exit", address: 100000610, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +132: Symbol { name: ".exit", address: 100000610, size: 28, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 134: Symbol { name: ".exit", address: 100000610, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 136: Symbol { name: "glink64.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -137: Symbol { name: ".__run_final_dtors", address: 100000598, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +137: Symbol { name: ".__run_final_dtors", address: 100000598, size: 28, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 139: Symbol { name: ".__run_final_dtors", address: 100000598, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 141: Symbol { name: "glink64.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -142: Symbol { name: ".atexit", address: 1000005c0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +142: Symbol { name: ".atexit", address: 1000005c0, size: 28, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 144: Symbol { name: ".atexit", address: 1000005c0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 146: Symbol { name: "glink64.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -147: Symbol { name: ".__run_initial_ctors", address: 1000005e8, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +147: Symbol { name: ".__run_initial_ctors", address: 1000005e8, size: 28, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 149: Symbol { name: ".__run_initial_ctors", address: 1000005e8, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 151: Symbol { name: "glink64.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -152: Symbol { name: ".printf", address: 100000698, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +152: Symbol { name: ".printf", address: 100000698, size: 28, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 154: Symbol { name: ".printf", address: 100000698, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } .text relocations diff --git a/crates/examples/testfiles/xcoff/base32.o.objdump b/crates/examples/testfiles/xcoff/base32.o.objdump index f1094080..f6f10acc 100644 --- a/crates/examples/testfiles/xcoff/base32.o.objdump +++ b/crates/examples/testfiles/xcoff/base32.o.objdump @@ -11,12 +11,12 @@ Symbols 0: Symbol { name: ".file", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } 3: Symbol { name: ".printf", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: None } 5: Symbol { name: "printf", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: None } -7: Symbol { name: ".text", address: 0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +7: Symbol { name: ".text", address: 0, size: 5b, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 9: Symbol { name: ".main", address: 0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -11: Symbol { name: ".rodata.str1.1L...str", address: 5c, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -13: Symbol { name: "main", address: 6c, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +11: Symbol { name: ".rodata.str1.1L...str", address: 5c, size: d, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +13: Symbol { name: "main", address: 6c, size: c, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } 15: Symbol { name: "TOC", address: 78, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -17: Symbol { name: ".rodata.str1.1L...str", address: 78, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +17: Symbol { name: ".rodata.str1.1L...str", address: 78, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } .text relocations (22, Relocation { kind: Got, encoding: Generic, size: 0, target: Symbol(SymbolIndex(11)), addend: 0, implicit_addend: true }) diff --git a/crates/examples/testfiles/xcoff/base32.xcoff.objdump b/crates/examples/testfiles/xcoff/base32.xcoff.objdump index 8d45ba8a..4b9dbf39 100644 --- a/crates/examples/testfiles/xcoff/base32.xcoff.objdump +++ b/crates/examples/testfiles/xcoff/base32.xcoff.objdump @@ -20,72 +20,72 @@ Symbols 14: Symbol { name: "__crt0v", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: None } 16: Symbol { name: "__malloc_user_defined_name", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: None } 18: Symbol { name: "TOC", address: 20000748, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -20: Symbol { name: "__crt0v", address: 20000770, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -22: Symbol { name: "__mod_init", address: 20000774, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -24: Symbol { name: "crt0_data", address: 20000778, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -26: Symbol { name: "__run_final_dtors", address: 2000077c, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -28: Symbol { name: "_$STATIC", address: 20000780, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -30: Symbol { name: "__C_runtime_termination", address: 20000784, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -32: Symbol { name: "atexit", address: 20000788, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -34: Symbol { name: "_cdtors", address: 2000078c, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -36: Symbol { name: "__run_initial_ctors", address: 20000790, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -38: Symbol { name: "exit", address: 20000794, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -40: Symbol { name: "__malloc_user_defined_name", address: 20000798, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -42: Symbol { name: "errno", address: 2000079c, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -44: Symbol { name: ".rodata.str1.1L...str", address: 200007a0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -46: Symbol { name: "printf", address: 200007a4, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +20: Symbol { name: "__crt0v", address: 20000770, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +22: Symbol { name: "__mod_init", address: 20000774, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +24: Symbol { name: "crt0_data", address: 20000778, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +26: Symbol { name: "__run_final_dtors", address: 2000077c, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +28: Symbol { name: "_$STATIC", address: 20000780, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +30: Symbol { name: "__C_runtime_termination", address: 20000784, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +32: Symbol { name: "atexit", address: 20000788, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +34: Symbol { name: "_cdtors", address: 2000078c, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +36: Symbol { name: "__run_initial_ctors", address: 20000790, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +38: Symbol { name: "exit", address: 20000794, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +40: Symbol { name: "__malloc_user_defined_name", address: 20000798, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +42: Symbol { name: "errno", address: 2000079c, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +44: Symbol { name: ".rodata.str1.1L...str", address: 200007a0, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +46: Symbol { name: "printf", address: 200007a4, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } 48: Symbol { name: " ", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } 49: Symbol { name: "crt0main.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -50: Symbol { name: ".__start", address: 10000128, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +50: Symbol { name: ".__start", address: 10000128, size: a5, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 52: Symbol { name: ".__start", address: 10000128, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -54: Symbol { name: "__start", address: 20000710, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -56: Symbol { name: "crt0_data", address: 200005f4, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -58: Symbol { name: "p_xargc", address: 2000074c, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -60: Symbol { name: "p_xargv", address: 20000764, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -62: Symbol { name: "p_xrcfg", address: 20000768, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -64: Symbol { name: "p_xrc", address: 2000076c, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -66: Symbol { name: "_malloc_user_defined_name", address: 20000748, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +54: Symbol { name: "__start", address: 20000710, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +56: Symbol { name: "crt0_data", address: 200005f4, size: 2c, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +58: Symbol { name: "p_xargc", address: 2000074c, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +60: Symbol { name: "p_xargv", address: 20000764, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +62: Symbol { name: "p_xrcfg", address: 20000768, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +64: Symbol { name: "p_xrc", address: 2000076c, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +66: Symbol { name: "_malloc_user_defined_name", address: 20000748, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } 68: Symbol { name: ".file", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -72: Symbol { name: "", address: 100001e0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +72: Symbol { name: "", address: 100001e0, size: 160, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 74: Symbol { name: ".__threads_init", address: 100001e0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 76: Symbol { name: ".__threads_init@AF2_1", address: 10000220, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -78: Symbol { name: "_$STATIC", address: 20000620, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -80: Symbol { name: "__threads_init", address: 20000718, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -82: Symbol { name: "__pth_init_routine", address: 20000750, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -84: Symbol { name: "_bsd_init_routine", address: 20000754, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -86: Symbol { name: "_xti_tli_init_routine", address: 20000758, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -88: Symbol { name: "_nsl_init_routine", address: 2000075c, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -90: Symbol { name: "__dce_compat_init_routine", address: 20000760, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +78: Symbol { name: "_$STATIC", address: 20000620, size: 59, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +80: Symbol { name: "__threads_init", address: 20000718, size: c, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +82: Symbol { name: "__pth_init_routine", address: 20000750, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +84: Symbol { name: "_bsd_init_routine", address: 20000754, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +86: Symbol { name: "_xti_tli_init_routine", address: 20000758, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +88: Symbol { name: "_nsl_init_routine", address: 2000075c, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +90: Symbol { name: "__dce_compat_init_routine", address: 20000760, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } 92: Symbol { name: ".file", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -96: Symbol { name: "", address: 10000340, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +96: Symbol { name: "", address: 10000340, size: 178, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 98: Symbol { name: ".__User_sinit_begin", address: 10000340, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 100: Symbol { name: ".__C_runtime_termination", address: 10000368, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 102: Symbol { name: ".__C_runtime_startup", address: 100003b8, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 104: Symbol { name: ".__dftdt__L304e4b28c42_5CatchFv", address: 10000440, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -106: Symbol { name: "_$STATIC", address: 20000680, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -108: Symbol { name: "__dftdt__L304e4b28c42_5CatchFv", address: 20000730, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -110: Symbol { name: "__C_runtime_termination", address: 2000073c, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -112: Symbol { name: "__C_runtime_startup", address: 20000724, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } -114: Symbol { name: "_cdtors", address: 20000708, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: true, flags: None } -116: Symbol { name: "__C_runtime_pstartup", address: 2000067c, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +106: Symbol { name: "_$STATIC", address: 20000680, size: 81, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +108: Symbol { name: "__dftdt__L304e4b28c42_5CatchFv", address: 20000730, size: c, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +110: Symbol { name: "__C_runtime_termination", address: 2000073c, size: c, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +112: Symbol { name: "__C_runtime_startup", address: 20000724, size: c, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } +114: Symbol { name: "_cdtors", address: 20000708, size: 8, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: true, flags: None } +116: Symbol { name: "__C_runtime_pstartup", address: 2000067c, size: 4, kind: Data, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: None } 118: Symbol { name: ".file", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -121: Symbol { name: ".text", address: 10000560, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +121: Symbol { name: ".text", address: 10000560, size: 5b, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 123: Symbol { name: ".main", address: 10000560, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } -125: Symbol { name: ".rodata.str1.1L...str", address: 100005e4, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +125: Symbol { name: ".rodata.str1.1L...str", address: 100005e4, size: d, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 127: Symbol { name: "glink.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -128: Symbol { name: ".exit", address: 10000530, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +128: Symbol { name: ".exit", address: 10000530, size: 28, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 130: Symbol { name: ".exit", address: 10000530, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 132: Symbol { name: "glink.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -133: Symbol { name: ".__run_final_dtors", address: 100004b8, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +133: Symbol { name: ".__run_final_dtors", address: 100004b8, size: 28, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 135: Symbol { name: ".__run_final_dtors", address: 100004b8, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 137: Symbol { name: "glink.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -138: Symbol { name: ".atexit", address: 100004e0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +138: Symbol { name: ".atexit", address: 100004e0, size: 28, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 140: Symbol { name: ".atexit", address: 100004e0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 142: Symbol { name: "glink.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -143: Symbol { name: ".__run_initial_ctors", address: 10000508, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +143: Symbol { name: ".__run_initial_ctors", address: 10000508, size: 28, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 145: Symbol { name: ".__run_initial_ctors", address: 10000508, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 147: Symbol { name: "glink.s", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: None } -148: Symbol { name: ".printf", address: 100005bc, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } +148: Symbol { name: ".printf", address: 100005bc, size: 28, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } 150: Symbol { name: ".printf", address: 100005bc, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: None } .text relocations diff --git a/src/read/xcoff/file.rs b/src/read/xcoff/file.rs index 9631cce3..bac9e707 100644 --- a/src/read/xcoff/file.rs +++ b/src/read/xcoff/file.rs @@ -11,9 +11,9 @@ use crate::{ }; use super::{ - SectionHeader, SectionTable, Symbol, SymbolTable, XcoffComdat, XcoffComdatIterator, - XcoffSection, XcoffSectionIterator, XcoffSegment, XcoffSegmentIterator, XcoffSymbol, - XcoffSymbolIterator, XcoffSymbolTable, + CsectAux, FileAux, SectionHeader, SectionTable, Symbol, SymbolTable, XcoffComdat, + XcoffComdatIterator, XcoffSection, XcoffSectionIterator, XcoffSegment, XcoffSegmentIterator, + XcoffSymbol, XcoffSymbolIterator, XcoffSymbolTable, }; /// A 32-bit XCOFF object file. @@ -248,6 +248,8 @@ pub trait FileHeader: Debug + Pod { type AuxHeader: AuxHeader; type SectionHeader: SectionHeader; type Symbol: Symbol; + type FileAux: FileAux; + type CsectAux: CsectAux; /// Return true if this type is a 64-bit header. fn is_type_64(&self) -> bool; @@ -328,6 +330,8 @@ impl FileHeader for xcoff::FileHeader32 { type AuxHeader = xcoff::AuxHeader32; type SectionHeader = xcoff::SectionHeader32; type Symbol = xcoff::Symbol32; + type FileAux = xcoff::FileAux32; + type CsectAux = xcoff::CsectAux32; fn is_type_64(&self) -> bool { false @@ -367,6 +371,8 @@ impl FileHeader for xcoff::FileHeader64 { type AuxHeader = xcoff::AuxHeader64; type SectionHeader = xcoff::SectionHeader64; type Symbol = xcoff::Symbol64; + type FileAux = xcoff::FileAux64; + type CsectAux = xcoff::CsectAux64; fn is_type_64(&self) -> bool { true diff --git a/src/read/xcoff/symbol.rs b/src/read/xcoff/symbol.rs index 692e3341..3a7c7f18 100644 --- a/src/read/xcoff/symbol.rs +++ b/src/read/xcoff/symbol.rs @@ -1,16 +1,17 @@ use alloc::fmt; use core::convert::TryInto; use core::fmt::Debug; +use core::marker::PhantomData; use core::str; use crate::endian::{BigEndian as BE, U32Bytes}; use crate::pod::Pod; use crate::read::util::StringTable; -use crate::{xcoff, Object, ObjectSection, SectionKind}; +use crate::{bytes_of, xcoff, Object, ObjectSection, SectionKind}; use crate::read::{ - self, ObjectSymbol, ObjectSymbolTable, ReadError, ReadRef, Result, SectionIndex, SymbolFlags, - SymbolIndex, SymbolKind, SymbolScope, SymbolSection, + self, Bytes, Error, ObjectSymbol, ObjectSymbolTable, ReadError, ReadRef, Result, SectionIndex, + SymbolFlags, SymbolIndex, SymbolKind, SymbolScope, SymbolSection, }; use super::{FileHeader, XcoffFile}; @@ -24,8 +25,9 @@ where Xcoff: FileHeader, R: ReadRef<'data>, { - symbols: &'data [Xcoff::Symbol], + symbols: &'data [xcoff::SymbolBytes], strings: StringTable<'data, R>, + header: PhantomData, } impl<'data, Xcoff, R> Default for SymbolTable<'data, Xcoff, R> @@ -37,6 +39,7 @@ where Self { symbols: &[], strings: StringTable::default(), + header: PhantomData, } } } @@ -70,14 +73,50 @@ where (&[][..], StringTable::default()) }; - Ok(SymbolTable { symbols, strings }) + Ok(SymbolTable { + symbols, + strings, + header: PhantomData, + }) + } + + /// Return the symbol entry at the given index and offset. + pub fn get(&self, index: usize, offset: usize) -> Result<&'data T> { + let entry = index + .checked_add(offset) + .and_then(|x| self.symbols.get(x)) + .read_error("Invalid XCOFF symbol index")?; + let bytes = bytes_of(entry); + Bytes(bytes).read().read_error("Invalid XCOFF symbol data") } /// Return the symbol at the given index. - pub fn symbol(&self, index: usize) -> read::Result<&'data Xcoff::Symbol> { - self.symbols - .get(index) - .read_error("Invalid XCOFF symbol index") + pub fn symbol(&self, index: usize) -> Result<&'data Xcoff::Symbol> { + self.get::(index, 0) + } + + /// Return the file auxiliary symbol. + pub fn aux_file(&self, index: usize) -> Result<&'data Xcoff::FileAux> { + debug_assert!(self.symbol(index)?.has_aux_file()); + let aux_file = self.get::(index, 1)?; + if let Some(aux_type) = aux_file.x_auxtype() { + if aux_type != xcoff::AUX_FILE { + return Err(Error("Invalid index for file auxiliary symbol.")); + } + } + return Ok(aux_file); + } + + /// Return the csect auxiliary symbol. + pub fn aux_csect(&self, index: usize, offset: usize) -> Result<&'data Xcoff::CsectAux> { + debug_assert!(self.symbol(index)?.has_aux_csect()); + let aux_csect = self.get::(index, offset)?; + if let Some(aux_type) = aux_csect.x_auxtype() { + if aux_type != xcoff::AUX_CSECT { + return Err(Error("Invalid index/offset for csect auxiliary symbol.")); + } + } + return Ok(aux_csect); } /// Return true if the symbol table is empty. @@ -178,7 +217,7 @@ impl<'data, 'file, Xcoff: FileHeader, R: ReadRef<'data>> Iterator fn next(&mut self) -> Option { let index = self.index; - let symbol = self.symbols.symbols.get(index)?; + let symbol = self.symbols.symbol(index).ok()?; // TODO: skip over the auxiliary symbols for now. self.index += 1 + symbol.n_numaux() as usize; Some(XcoffSymbol { @@ -251,9 +290,26 @@ impl<'data, 'file, Xcoff: FileHeader, R: ReadRef<'data>> ObjectSymbol<'data> #[inline] fn size(&self) -> u64 { - // TODO: get the symbol size when the csect auxiliary symbol is supported. - // Most symbols don't have sizes. - 0 + if self.symbol.has_aux_csect() { + // XCOFF32 must have the csect auxiliary entry as the last auxiliary entry. + // XCOFF64 doesn't require this, but conventionally does. + if let Ok(aux_csect) = self + .file + .symbols + .aux_csect(self.index.0, self.symbol.n_numaux() as usize) + { + let sym_type = aux_csect.sym_type() & 0x07; + if sym_type == xcoff::XTY_SD || sym_type == xcoff::XTY_CM { + aux_csect.x_scnlen() + } else { + 0 + } + } else { + 0 + } + } else { + 0 + } } fn kind(&self) -> SymbolKind { @@ -288,9 +344,25 @@ impl<'data, 'file, Xcoff: FileHeader, R: ReadRef<'data>> ObjectSymbol<'data> self.symbol.is_undefined() } + /// Return true if the symbol is a definition of a function or data object. #[inline] fn is_definition(&self) -> bool { - self.symbol.is_definition() + if self.symbol.has_aux_csect() { + if let Ok(aux_csect) = self + .symbols + .aux_csect(self.index.0, self.symbol.n_numaux() as usize) + { + let smclas = aux_csect.x_smclas(); + self.symbol.n_scnum() != xcoff::N_UNDEF + && (smclas == xcoff::XMC_PR + || smclas == xcoff::XMC_RW + || smclas == xcoff::XMC_RO) + } else { + false + } + } else { + false + } } #[inline] @@ -364,10 +436,19 @@ pub trait Symbol: Debug + Pod { && self.n_scnum() == xcoff::N_UNDEF } - /// Return true if the symbol is a definition of a function or data object. - /// TODO: get the x_smtyp value when csect auxiliary symbol is supported. - fn is_definition(&self) -> bool { - self.n_scnum() != xcoff::N_UNDEF + /// Return true if the symbol has file auxiliary entry. + fn has_aux_file(&self) -> bool { + self.n_numaux() > 0 && self.n_sclass() == xcoff::C_FILE + } + + /// Return true if the symbol has csect auxiliary entry. + /// + /// A csect auxiliary entry is required for each symbol table entry that has + /// a storage class value of C_EXT, C_WEAKEXT, or C_HIDEXT. + fn has_aux_csect(&self) -> bool { + let sclass = self.n_sclass(); + self.n_numaux() > 0 + && (sclass == xcoff::C_EXT || sclass == xcoff::C_WEAKEXT || sclass == xcoff::C_HIDEXT) } } @@ -448,3 +529,106 @@ impl Symbol for xcoff::Symbol32 { } } } + +/// A trait for generic access to `FileAux32` and `FileAux64`. +#[allow(missing_docs)] +pub trait FileAux: Debug + Pod { + fn x_fname(&self) -> &[u8; 8]; + fn x_ftype(&self) -> u8; + fn x_auxtype(&self) -> Option; +} + +impl FileAux for xcoff::FileAux64 { + fn x_fname(&self) -> &[u8; 8] { + &self.x_fname + } + + fn x_ftype(&self) -> u8 { + self.x_ftype + } + + fn x_auxtype(&self) -> Option { + Some(self.x_auxtype) + } +} + +impl FileAux for xcoff::FileAux32 { + fn x_fname(&self) -> &[u8; 8] { + &self.x_fname + } + + fn x_ftype(&self) -> u8 { + self.x_ftype + } + + fn x_auxtype(&self) -> Option { + None + } +} + +/// A trait for generic access to `CsectAux32` and `CsectAux64`. +#[allow(missing_docs)] +pub trait CsectAux: Debug + Pod { + fn x_scnlen(&self) -> u64; + fn x_parmhash(&self) -> u32; + fn x_snhash(&self) -> u16; + fn x_smtyp(&self) -> u8; + fn x_smclas(&self) -> u8; + fn x_auxtype(&self) -> Option; + + fn sym_type(&self) -> u8 { + self.x_smtyp() & 0x07 + } +} + +impl CsectAux for xcoff::CsectAux64 { + fn x_scnlen(&self) -> u64 { + self.x_scnlen_lo.get(BE) as u64 | ((self.x_scnlen_hi.get(BE) as u64) << 32) + } + + fn x_parmhash(&self) -> u32 { + self.x_parmhash.get(BE) + } + + fn x_snhash(&self) -> u16 { + self.x_snhash.get(BE) + } + + fn x_smtyp(&self) -> u8 { + self.x_smtyp + } + + fn x_smclas(&self) -> u8 { + self.x_smclas + } + + fn x_auxtype(&self) -> Option { + Some(self.x_auxtype) + } +} + +impl CsectAux for xcoff::CsectAux32 { + fn x_scnlen(&self) -> u64 { + self.x_scnlen.get(BE) as u64 + } + + fn x_parmhash(&self) -> u32 { + self.x_parmhash.get(BE) + } + + fn x_snhash(&self) -> u16 { + self.x_snhash.get(BE) + } + + fn x_smtyp(&self) -> u8 { + self.x_smtyp + } + + fn x_smclas(&self) -> u8 { + self.x_smclas + } + + fn x_auxtype(&self) -> Option { + None + } +} diff --git a/src/xcoff.rs b/src/xcoff.rs index b9dee28c..4724f8ef 100644 --- a/src/xcoff.rs +++ b/src/xcoff.rs @@ -5,6 +5,8 @@ //! //! This module is the equivalent of /usr/include/xcoff.h, and is based heavily on it. +#![allow(missing_docs)] + use crate::endian::{BigEndian as BE, I16, U16, U32, U64}; use crate::pod::Pod; @@ -329,6 +331,12 @@ pub const STYP_TYPCHK: u16 = 0x4000; /// when either of the counts exceeds 65,534. pub const STYP_OVRFLO: u16 = 0x8000; +pub const SIZEOF_SYMBOL: usize = 18; + +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct SymbolBytes(pub [u8; SIZEOF_SYMBOL]); + /// Symbol table entry. #[derive(Debug, Clone, Copy)] #[repr(C)] @@ -382,13 +390,9 @@ pub const N_UNDEF: i16 = 0; /// of the 16-bit unsigned n_type field of symbol table entries. Valid for /// 32-bit XCOFF only when the o_vstamp in the auxiliary header is greater than 1. pub const SYM_V_MASK: u16 = 0xF000; -#[allow(missing_docs)] pub const SYM_V_INTERNAL: u16 = 0x1000; -#[allow(missing_docs)] pub const SYM_V_HIDDEN: u16 = 0x2000; -#[allow(missing_docs)] pub const SYM_V_PROTECTED: u16 = 0x3000; -#[allow(missing_docs)] pub const SYM_V_EXPORTED: u16 = 0x4000; // Values for `n_sclass`. @@ -506,6 +510,51 @@ pub const C_EFCN: u8 = 255; /// Reserved. pub const C_TCSYM: u8 = 134; +/// File Auxiliary Entry for C_FILE Symbols. +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct FileAux32 { + /// The source file name or compiler-related string. + /// + /// If first 4 bytes are 0, then second 4 bytes are offset into string table. + pub x_fname: [u8; 8], + /// Pad size for file name. + pub x_fpad: [u8; 6], + /// The source-file string type. + pub x_ftype: u8, + /// Reserved. + pub x_freserve: [u8; 3], +} + +/// File Auxiliary Entry for C_FILE Symbols. +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct FileAux64 { + /// The source file name or compiler-related string. + /// + /// If first 4 bytes are 0, then second 4 bytes are offset into string table. + pub x_fname: [u8; 8], + /// Pad size for file name. + pub x_fpad: [u8; 6], + /// The source-file string type. + pub x_ftype: u8, + /// Reserved. + pub x_freserve: [u8; 2], + /// Specifies the type of auxiliary entry. Contains _AUX_FILE for this auxiliary entry. + pub x_auxtype: u8, +} + +// Values for `x_ftype`. +// +/// Specifies the source-file name. +pub const XFT_FN: u8 = 0; +/// Specifies the compiler time stamp. +pub const XFT_CT: u8 = 1; +/// Specifies the compiler version number. +pub const XFT_CV: u8 = 2; +/// Specifies compiler-defined information. +pub const XFT_CD: u8 = 128; + /// Csect auxiliary entry for C_EXT, C_WEAKEXT, and C_HIDEXT symbols. #[derive(Debug, Clone, Copy)] #[repr(C)] @@ -548,6 +597,198 @@ pub struct CsectAux64 { pub x_auxtype: u8, } +// Values for `x_smtyp`. +// +/// External reference. +pub const XTY_ER: u8 = 0; +/// Csect definition for initialized storage. +pub const XTY_SD: u8 = 1; +/// Defines an entry point to an initialized csect. +pub const XTY_LD: u8 = 2; +/// Common csect definition. For uninitialized storage. +pub const XTY_CM: u8 = 3; + +// Values for `x_smclas`. +// +// READ ONLY CLASSES +// +/// Program Code +pub const XMC_PR: u8 = 0; +/// Read Only Constant +pub const XMC_RO: u8 = 1; +/// Debug Dictionary Table +pub const XMC_DB: u8 = 2; +/// Global Linkage (Interfile Interface Code) +pub const XMC_GL: u8 = 6; +/// Extended Operation (Pseudo Machine Instruction) +pub const XMC_XO: u8 = 7; +/// Supervisor Call (32-bit process only) +pub const XMC_SV: u8 = 8; +/// Supervisor Call for 64-bit process +pub const XMC_SV64: u8 = 17; +/// Supervisor Call for both 32- and 64-bit processes +pub const XMC_SV3264: u8 = 18; +/// Traceback Index csect +pub const XMC_TI: u8 = 12; +/// Traceback Table csect +pub const XMC_TB: u8 = 13; +// +// READ WRITE CLASSES +// +/// Read Write Data +pub const XMC_RW: u8 = 5; +/// TOC Anchor for TOC Addressability +pub const XMC_TC0: u8 = 15; +/// General TOC item +pub const XMC_TC: u8 = 3; +/// Scalar data item in the TOC +pub const XMC_TD: u8 = 16; +/// Descriptor csect +pub const XMC_DS: u8 = 10; +/// Unclassified - Treated as Read Write +pub const XMC_UA: u8 = 4; +/// BSS class (uninitialized static internal) +pub const XMC_BS: u8 = 9; +/// Un-named Fortran Common +pub const XMC_UC: u8 = 11; +/// Initialized thread-local variable +pub const XMC_TL: u8 = 20; +/// Uninitialized thread-local variable +pub const XMC_UL: u8 = 21; +/// Symbol mapped at the end of TOC +pub const XMC_TE: u8 = 22; + +/// Function auxiliary entry. +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct FunAux32 { + /// File offset to exception table entry. + pub x_exptr: U32, + /// Size of function in bytes. + pub x_fsize: U32, + /// File pointer to line number + pub x_lnnoptr: U32, + /// Symbol table index of next entry beyond this function. + pub x_endndx: U32, + /// Pad + pub pad: U16, +} + +/// Function auxiliary entry. +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct FunAux64 { + /// File pointer to line number + pub x_lnnoptr: U64, + /// Size of function in bytes. + pub x_fsize: U32, + /// Symbol table index of next entry beyond this function. + pub x_endndx: U32, + /// Pad + pub pad: u8, + /// Contains _AUX_FCN; Type of auxiliary entry. + pub x_auxtype: u8, +} + +/// Exception auxiliary entry. (XCOFF64 only) +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct ExpAux { + /// File offset to exception table entry. + pub x_exptr: U64, + /// Size of function in bytes. + pub x_fsize: U32, + /// Symbol table index of next entry beyond this function. + pub x_endndx: U32, + /// Pad + pub pad: u8, + /// Contains _AUX_EXCEPT; Type of auxiliary entry + pub x_auxtype: u8, +} + +/// Block auxiliary entry for the C_BLOCK and C_FCN Symbols. +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct BlockAux32 { + /// Reserved. + pub pad: [u8; 2], + /// High-order 2 bytes of the source line number. + pub x_lnnohi: U16, + /// Low-order 2 bytes of the source line number. + pub x_lnnolo: U16, + /// Reserved. + pub pad2: [u8; 12], +} + +/// Block auxiliary entry for the C_BLOCK and C_FCN Symbols. +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct BlockAux64 { + /// Source line number. + pub x_lnno: U32, + /// Reserved. + pub pad: [u8; 13], + /// Contains _AUX_SYM; Type of auxiliary entry. + pub x_auxtype: u8, +} + +/// Section auxiliary entry for the C_STAT Symbol. (XCOFF32 Only) +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct StatAux { + /// Section length. + pub x_scnlen: U32, + /// Number of relocation entries. + pub x_nreloc: U16, + /// Number of line numbers. + pub x_nlinno: U16, + /// Reserved. + pub pad: [u8; 10], +} + +/// Section auxiliary entry Format for C_DWARF symbols. +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct DwarfAux32 { + /// Length of portion of section represented by symbol. + pub x_scnlen: U32, + /// Reserved. + pub pad: [u8; 4], + /// Number of relocation entries in section. + pub x_nreloc: U32, + /// Reserved. + pub pad2: [u8; 6], +} + +/// Section auxiliary entry Format for C_DWARF symbols. +#[derive(Debug, Clone, Copy)] +#[repr(C)] +pub struct DwarfAux64 { + /// Length of portion of section represented by symbol. + pub x_scnlen: U64, + /// Number of relocation entries in section. + pub x_nreloc: U64, + /// Reserved. + pub pad: u8, + /// Contains _AUX_SECT; Type of Auxillary entry. + pub x_auxtype: u8, +} + +// Values for `x_auxtype` +// +/// Identifies an exception auxiliary entry. +pub const AUX_EXCEPT: u8 = 255; +/// Identifies a function auxiliary entry. +pub const AUX_FCN: u8 = 254; +/// Identifies a symbol auxiliary entry. +pub const AUX_SYM: u8 = 253; +/// Identifies a file auxiliary entry. +pub const AUX_FILE: u8 = 252; +/// Identifies a csect auxiliary entry. +pub const AUX_CSECT: u8 = 251; +/// Identifies a SECT auxiliary entry. +pub const AUX_SECT: u8 = 250; + /// Relocation table entry #[derive(Debug, Clone, Copy)] #[repr(C)] @@ -632,10 +873,21 @@ unsafe_impl_pod!( AuxHeader64, SectionHeader32, SectionHeader64, + SymbolBytes, Symbol32, Symbol64, + FileAux32, + FileAux64, CsectAux32, CsectAux64, + FunAux32, + FunAux64, + ExpAux, + BlockAux32, + BlockAux64, + StatAux, + DwarfAux32, + DwarfAux64, Rel32, Rel64, );