Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add copyright notices to WASM files? #14148

Closed
jeffRTC opened this issue May 11, 2021 · 7 comments
Closed

How to add copyright notices to WASM files? #14148

jeffRTC opened this issue May 11, 2021 · 7 comments

Comments

@jeffRTC
Copy link

jeffRTC commented May 11, 2021

Is there a safe way to add copyright notices to WASM files?

Preferably, I'd like to add it to top of WASM file.

@sbc100
Copy link
Collaborator

sbc100 commented May 29, 2021

Yes, you could add a custom section. I'm not sure what the best tool to inject a custom section is ... perhaps its already possible with llvm-objcopy (@dschuff can we do this already?, if not we should add it).

@sbc100
Copy link
Collaborator

sbc100 commented May 29, 2021

Custom section can appear anywhere in the wasm file and WMs will ignore then.

@jeffRTC
Copy link
Author

jeffRTC commented Jun 1, 2021

Good to know but can't find a tool to inject custom section. An example with llvm-objcopy would be appreciated.

@dschuff
Copy link
Member

dschuff commented Jun 1, 2021

Yes, llvm-objcopy can do this. For example, suppose you have a wasm file:

$ llvm-objdump -h hello.wasm

hello.wasm:	file format wasm

Sections:
Idx Name          Size     VMA      Type
  0 TYPE          00000157 00000000
  1 IMPORT        00000261 00000000
  2 FUNCTION      00000072 00000000
  3 TABLE         00000005 00000000
  4 GLOBAL        00000044 00000000
  5 EXPORT        0000036b 00000000
  6 START         00000001 00000000
  7 ELEM          0000000c 00000000
  8 DATACOUNT     00000001 00000000
  9 CODE          00006774 00000000 TEXT
 10 DATA          00000d3e 00000000 DATA

You can put your content into a file:

$ echo "Hello!" > hello.txt

And append it to your binary:
llvm-objcopy --add-section=HelloSection=hello.txt hello.wasm hello2.wasm

And then see it:

$ llvm-objdump -h hello2.wasm

hello2.wasm:	file format wasm

Sections:
Idx Name          Size     VMA      Type
  0 TYPE          00000157 00000000
  1 IMPORT        00000261 00000000
  2 FUNCTION      00000072 00000000
  3 TABLE         00000005 00000000
  4 GLOBAL        00000044 00000000
  5 EXPORT        0000036b 00000000
  6 START         00000001 00000000
  7 ELEM          0000000c 00000000
  8 DATACOUNT     00000001 00000000
  9 CODE          00006774 00000000 TEXT
 10 DATA          00000d3e 00000000 DATA
 11 HelloSection  00000007 00000000

And also look inside it:

llvm-objdump --full-contents --section=HelloSection hello2.wasm

hello2.wasm:	file format wasm

Contents of section HelloSection:
 0000 48656c6c 6f210a                      Hello!.

@sbc100
Copy link
Collaborator

sbc100 commented Jun 1, 2021

Thanks @dschuff .. pretty awesome how that just works.

@jeffRTC
Copy link
Author

jeffRTC commented Jun 4, 2021

@sbc100 Should I close this or do you have any plans to add this to Emscripten itself?

@sbc100
Copy link
Collaborator

sbc100 commented Jun 4, 2021

No please close. It would be nice to document how to do this somewhere, but I'm not sure emscripten is the right place for since it would apply to any clang-based WebAssembly toolchain.

@sbc100 sbc100 closed this as completed Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants