xoofx / LibObjectFile

LibObjectFile is a .NET library to read, manipulate and write linker and executable object files (e.g ELF, PE, DWARF, ar...)
BSD 2-Clause "Simplified" License
159 stars 11 forks source link

Update unit tests and fix bugs to make them pass again #32

Closed filipnavara closed 1 year ago

filipnavara commented 1 year ago

Tested on Windows with Ubuntu 22.04 installed in WSL.

xoofx commented 1 year ago

Amazing, thanks a lot for this!

am11 commented 1 year ago

@filipnavara, in case this is not known, I ran tests (dotnet test src/LibObjectFile.Tests) on linux-arm64 (Ubuntu 22.04), four tests are failing. Here is the output http://sprunge.us/9szZoA. e.g.


  Failed TestDebugInfoSmall [32 ms]
  Error Message:
   System.NotImplementedException : The relocation for architecture EM_AARCH64 is not supported/implemented.
  Stack Trace:
     at LibObjectFile.Elf.ElfRelocationTableExtensions.Relocate(ElfRelocationTable relocTable, Stream stream, ElfRelocationContext& context) in /LibObjectFile/src/LibObjectFile/Elf/Sections/ElfRelocationTableExtensions.cs:line 45
   at LibObjectFile.Elf.ElfRelocationTableExtensions.Relocate(ElfRelocationTable relocTable, ElfRelocationContext& context) in /LibObjectFile/src/LibObjectFile/Elf/Sections/ElfRelocationTableExtensions.cs:line 28
   at LibObjectFile.Dwarf.DwarfElfContext..ctor(ElfObjectFile elf) in /LibObjectFile/src/LibObjectFile/Dwarf/DwarfElfContext.cs:line 102
   at LibObjectFile.Tests.Dwarf.DwarfTests.TestDebugInfoSmall() in /LibObjectFile/src/LibObjectFile.Tests/Dwarf/DwarfTests.cs:line 326
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
filipnavara commented 1 year ago

Yeah, the tests kinda work only on x64 and specific Ubuntu version (or the same version under WSL). They are extremely fragile since they compare readelf output (which changes with Binutils versions), and gcc-compiled objects. In this case the gcc output is arm64 and not the x64 one that is expected, and since gcc is not naturally a cross-compiler it's not easy to fix with a single flag.

TL;DR: The tests are fixed only enough to pass on Ubuntu 22.04 on x64, or Windows x64 with Ubuntu 22.04 in WSL. Anything else is going to fail one way or another.