3 ms·
"step 4: use readelf" "$ ldd ./serve" "not a dynamic executable" No need to use ldd, can use readelf, as in step 4 $ readelf -d ./serve There is
by 1vuio0pswjnm7 5y ago
"step 4: use readelf"
"$ ldd ./serve"
"not a dynamic executable"
No need to use ldd, can use readelf, as in step 4
$ readelf -d ./serve
There is no dynamic section in this file.
http://www.catonmat.net/blog/ldd-arbitrary-code-execution/ http://www.catonmat.net/blog/ldd-arbitrary-code-execution/
"And statically linking in this case doesn't even produce a bigger binary (for some reason it seems to produce a slightly smaller binary?? I don't know why that is)"
To force use of built-in net libs instead of system ones, and remove debugging info to make the binary a little smaller, something like this
$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags '-w -extldflags "-static"' -o serve *.go
re: "File not found" I encounter this "weird bug" all the time because I like to build smaller, self-contained, no dependency systems and started doing so long before Docker existed. Static binaries are one way to solve the missing linker problem. Chroots and the like are another. I will sometimes create an alias that runs the program using chroot. Then I can keep the chroot directory as small as possible, populating it with only those resources the program actually needs. This is praticularly fun when it is an older program, no source available, and requires older versions of glibc, and other libraries. Dynamic linking in a time of GBs of core memory and TBs of storage is something I still question. People say dynamic linking is useful for the library "version control" it allows, but this just becomes a PITA for someone wanting to use older programs. Lots of folks compiling static binaries today for their Github repos only do so with glibc, which is hostile toward static linking. For someone using musl, this is no better than a dynamically-linked binary.