Sdk: dart2native: strip option

Created on 6 Oct 2019  路  8Comments  路  Source: dart-lang/sdk

Now that dart2native can create a single file, it would be nice if a way was
available for Dart to strip the created files. Currently I am using something
like this:

~
dart2native one.dart
strip one
~

I noticed that dartaotruntime itself has already been stripped, as its the
same size as a "hello world" example after you strip it yourself.

area-vm

Most helpful comment

@jamesderlin not with the current approach - the generated binary is essentially AOT runtime and an AOT snapshot simply concatenated together. strip just throws AOT snapshot away because it is not a real section.

All 8 comments

Hm, actually, it looks like stripping destroys the program:

~~~
$ cat one.dart
main() {
var bye = 'Hello world!';
print("$bye");
}

$ ./dart2native.bat one.dart
Generated: d:desktopdartsdk-windows-x64-releasedart-sdk\bin\one.exe

$ ./one.exe
Hello world!

$ strip one.exe
$ ./one.exe
Usage: dart [] []
~~~

I had a similar issue even without stripping, maybe it's related:

$ dart2native main.dart -o fireutil
Generated: /home/cachapa/fireutil/bin/fireutil

$ ./fireutil 
Utility to manage Firestore databases.
[...]

$ sudo mv fireutil /usr/local/bin
$ fireutil 
Usage: dart [<vm-flags>] <dart-script-file> [<script-arguments>]
[...]

To be fair, it fails with Go too:

~~~
$ cat one.go
package main
func main() {
println("hello world")
}

$ go build one.go
$ ./one.exe
hello world

$ strip one.exe
$ ./one.exe
sh: ./one.exe: cannot execute binary file: Exec format error
~~~

but it doesnt matter as Go has a strip option:

~
$ go build -ldflags -s one.go
$ ./one.exe
hello world
~

and it does work with D:

~~~
$ cat one.d
import std.stdio;
void main() {
writeln("hello world");
}

$ dmd one.d
$ ./one.exe
hello world

$ strip one.exe
$ ./one.exe
hello world
~~~

and works with Nim:

~~~
$ cat one.nim
echo "hello world"

$ nim c --gcc.exe:x86_64-w64-mingw32-gcc \

--gcc.linkerexe:x86_64-w64-mingw32-gcc one.nim
$ ./one.exe
hello world

$ strip one.exe
$ ./one.exe
hello world
~~~

@cup Can you confirm if UPX works with dart2native?

@0xbkt this issue is about strip, not UPX

https://wikipedia.org/wiki/Strip_(Unix)

strip is not going to do anything useful to the binary that dart2native produced so we have no plans to support it right now.

strip is not going to do anything useful to the binary that dart2native produced so we have no plans to support it right now.

Currently running strip not only is not useful, it's detrimental.

Is there anything we can do to at least make strip not break the generated binary?

@jamesderlin not with the current approach - the generated binary is essentially AOT runtime and an AOT snapshot simply concatenated together. strip just throws AOT snapshot away because it is not a real section.

Was this page helpful?
0 / 5 - 0 ratings