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

random magic value using modified cmd/link alternative #628

Merged
merged 8 commits into from
Jan 8, 2023

Conversation

pagran
Copy link
Member

@pagran pagran commented Jan 5, 2023

Alternative and in my opinion better implementation (previous - #623)

Applying git patch to modify magic value and in future strip runtime seemed good at first glance, but big problems surfaced when trying to implement it:

  1. Patch to update magic value twice dynamic, first dynamic value is original magic value ( changing between versions) and the magic value itself
  2. Magic value patch conflicts with the tiny flag and forces use of two different patches (and both are dynamic)
  3. Strip runtime via patches is a very bulky idea, because just removing print/println from runtime already means 500+ modifications in lots of files

Patches are good in linker because they are static (there are no flags like -tiny or dynamic values)
I think this implementation is a good balance between readability and convenience of patches and versatility of modifications through ast

@pagran pagran requested a review from mvdan January 5, 2023 19:54
Copy link
Member

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good to me - pretty thorough review below :)

I think your reasoning about AST vs plaintext patching is reasonable. git patching for pretty static stuff, but AST patching for dynamic (e.g. magic comparison) or mechanical (e.g. remove printlns) changes sounds like a good tradeoff.

Would like to see if @capnspacehook or @lu4p disagree with that hybrid patching strategy.

hash.go Outdated Show resolved Hide resolved
testdata/script/linker.txtar Outdated Show resolved Hide resolved
internal/linker/linker.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
internal/linker/linker.go Outdated Show resolved Hide resolved
main_test.go Outdated Show resolved Hide resolved
internal/linker/linker.go Show resolved Hide resolved
internal/linker/linker.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
internal/linker/linker.go Outdated Show resolved Hide resolved
@mvdan
Copy link
Member

mvdan commented Jan 7, 2023

Oh, and we probably need to add an item to the README's caveats section about the temporary dependency on git. If it's documented there with the link to the go-gitdiff issue, then the TODO in the code can simply point to the README.

internal/linker/linker.go Outdated Show resolved Hide resolved
internal/linker/linker.go Outdated Show resolved Hide resolved
- new line in linker.txtar
- magicValue doc
- GARBLE_LNK_MAGIC -> GARBLE_LINK_MAGIC
- name refactoring
- optimize runtime magic update
- optimize patch loading for 1 time GetPatch calling
- merge to lockedfile
@pagran pagran requested review from mvdan and lu4p January 8, 2023 12:16
Copy link
Member

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good now! Just some minor comments. My main concern is still the racy file lock.

internal/linker/linker.go Outdated Show resolved Hide resolved
internal/linker/linker.go Outdated Show resolved Hide resolved
internal/linker/linker.go Outdated Show resolved Hide resolved
internal/linker/linker.go Outdated Show resolved Hide resolved
runtime_patch.go Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
Copy link
Member

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@pagran
Copy link
Member Author

pagran commented Jan 8, 2023

Nice!

I forgot to update patch :)

@mvdan
Copy link
Member

mvdan commented Jan 8, 2023

Ah, let me know when you're ready. I was in the middle of squash-merging with a new commit message. You can also write the final commit message yourself, if you prefer.

@pagran
Copy link
Member Author

pagran commented Jan 8, 2023

Done. You write better commit messages :)

@mvdan mvdan merged commit 6ace033 into burrowers:master Jan 8, 2023
@mvdan
Copy link
Member

mvdan commented Jan 8, 2023

Written - let me know what you think or if I missed anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants