Skip to content

Conversation

@cornelk
Copy link
Contributor

@cornelk cornelk commented May 11, 2020

Tnis allows code that relies on it to compile, the flags package compiles now. No real parameters are passed but Args[0] contains a static mock string.

Setting Args as recommended #541 (comment) did not work tho:

tinygo/src/runtime/runtime_unix.go

func main() int {
	args = []string{"/proc/self/exe2"}
	preinit()
	run()

has no effect, os.Args will still hold the old value

@aykevl aykevl merged commit e907db1 into tinygo-org:dev May 12, 2020
@aykevl
Copy link
Member

aykevl commented May 12, 2020

Thank you, this is a welcome improvement to get more packages to compile (even if they aren't fully supported yet).

@cornelk cornelk deleted the os_args_stub branch May 12, 2020 14:59
@aykevl
Copy link
Member

aykevl commented May 12, 2020

I've looked a bit into why you can't initialize the arguments in runtime.main and there are two reasons:

  1. You can't do heap allocations before the initHeap call. This can be worked around by calling malloc directly.
  2. The interp package gets in the way. It assumes that all global variables are initialized with a package initializer (globals, init functions). Therefore, setting argumens in the main function at runtime will be ignored by package initializers, which often run at compile time (mainly for code size). This is tricky to solve, I'm not sure whether it can be solved without compiler changes.

@niaow niaow added this to the v0.14 milestone Jun 27, 2020
@sevki
Copy link

sevki commented Jul 9, 2020

@aykevl i saw this got merged, but it seems to break the dev branch with -gc=none is there another issue tracking the progress of this or work that needs to be done... I'm waiting to start a new job in a month so I have plenty of free time on my hands 😉

@aykevl
Copy link
Member

aykevl commented Jul 12, 2020

i saw this got merged, but it seems to break the dev branch with -gc=none

Are you sure this is what broke -gc=none? -gc=none is already broken in the master branch (and I believe it has been broken for a while now):

tinygo flash -target=pca10040 -gc=none examples/blinky1
Global is external, but doesn't have external or weak linkage!
i8* ()* @runtime.alloc
error: verification failure after LLVM optimization passes

@aykevl
Copy link
Member

aykevl commented Jul 12, 2020

Here is a PR to fix the -gc=none bug: #1236

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

Successfully merging this pull request may close these issues.

4 participants