wabt
wabt copied to clipboard
Roundtrip of object through ReadBinaryIR() -> WriteBinaryModule() result in : emnm : Error duplicate symbol.
If I make a roundtrip through wabt of an object file, then some objects from WriteBinaryModule() end up with:
emnm libskia.SkGeometry.o
/opt/emscripten-llvm/bin/llvm-nm: error: ./libskia.SkGeometry.o: duplicate symbol name sqrtf
I'm not really sure whats special about the sqrtf symbol in this object, but some of the other objects also have this issues for other symbols.
I'd be happy to send someone this object file to take a look at?
I had assumed a roundtrip through wabbt should result in the same file, if nothing is modified?
Best
James
Can you attach the object files?
Can you explain what you mean by "roudtripping" exactly? I'm pretty sure object files don't round trip because the contain a linking section with relocations that won't be preserved correctly/fully.
Can you attach the object files?
Can you explain what you mean by "roudtripping" exactly? I'm pretty sure object files don't round trip because the contain a linking section with relocations that won't be preserved correctly/fully.
@sbc100 Thanks for the quick response. Maybe the linking thing is something I'm having trouble with. What I'm trying to do is extract all objects from an archive, and prefix all defined symbols / functions, and then update all references to those symbols.
For simple examples I'm able to do this.
What is the restriction on handling real object files in wabt regarding the linking section? I've found the same restriction in binaryen too.
I've been unable to find a tool that can do this for wasm, do you know how I can achieve prefixing all symbols in a library?
Find the object here: https://github.com/jameswalmsley/filedump/raw/master/libskia.SkGeometry.o
To clarify roundtrip from my example.
I'm reading the entire object file with ReadBinaryIR(), not applying any changes, and then immediately writing back with WriteBinaryModule().
So I'm not going through a wat text file or anything like that.
Yeah the relocation data is not read into the IR as far I know, so that approach won't work.
If you are only looking at renaming symbols then a tool objcopy (llvm-obcopy) is probably more apporpiate here. It does look like it has flags for symbol redfining: https://sourceware.org/binutils/docs/binutils/objcopy.html:
Change the name of a symbol old, to new. This can be useful when one is trying link two things together for which you have no source, and there are name collisions.
--redefine-syms=filename
Apply --redefine-sym to each symbol pair "old new" listed in the file filename. filename is simply a flat file, with one symbol pair per line. Line comments may be introduced by the hash character. This option may be given more than once.
However, llvm-objcopy is fairly limited for the wasm target today so I'm not sure if these flags are yet working. I think it would be easier to fix any possible deficiencies in llvm-objcopy than to build full object file support into wabt/binaryen.
@sbc100 Thanks for the information.
I have tried llvm-objcopy and most of these flags aren't implemented yet. If you think its easier to do in llvm-objcopy I'll have a look to see if its possible to get something primitive up and running with that.
I had hoped to avoid coding llvm, because I wanted something as simple as possible, and then I found wabt.
Really nice project.
J
In a sense wabt is simpler yes. I think llvm-objcopy is the right tool for this job though, and you will probably be surprised how (relatively) simple the object file layer of llvm is (you don't need to worry about any of LLVM IR stuff to work on that). I'm happy to help out want to give it a go.
Trying to represent relocations in the wabt IR format,I think, would be quite a (comparatively) big task.
Ok many thanks. I'll find some time this week hopefully just to familiarise myself with the objcopy code in llvm.
Is there another channel (chat or email) that I can reach out to you best?
You can find me on the webassembly discord: https://discord.com/invite/nEFErF8
Closing as answered.