Go default LDFLAGS behavior
Hello, How are default LDFLAGS for Go ports applied considering they are set after they're included into the build command? I don't see those options in the output when running make and the resulting binary is in its standard size. However when I relocate the flag settings into the upper part of the script as in the provided diff, it works as expected and I get greeted with a shrunk binary. I think the default settings are skipped on the official build server too, because Go binaries on mirrors are similarly large. Could anyone clue me in if this behavior is still correct and I'm just misunderstanding something? Index: go.port.mk === RCS file: /cvs/ports/lang/go/go.port.mk,v retrieving revision 1.66 diff -u -p -r1.66 go.port.mk --- go.port.mk 21 Feb 2024 12:28:57 - 1.66 +++ go.port.mk 27 Feb 2024 15:23:27 - @@ -58,6 +58,11 @@ MODGO_LIST_CMD = ${MODGO_CMD} list ${MOD MODGO_TEST_CMD = ${MODGO_CMD} test ${MODGO_FLAGS} ${MODGO_TEST_FLAGS} MODGO_BINDIR ?=bin +.if empty(DEBUG) +# by default omit symbol table, debug information and DWARF symbol table +MODGO_LDFLAGS += -s -w +.endif + .if ! empty(MODGO_LDFLAGS) MODGO_BUILD_CMD += -ldflags="${MODGO_LDFLAGS}" MODGO_LIST_CMD += -ldflags="${MODGO_LDFLAGS}" @@ -111,10 +116,7 @@ CATEGORIES += lang/go MODGO_BUILD_TARGET = ${MODGO_BUILD_CMD} ${ALL_TARGET} MODGO_FLAGS += -v -buildvcs=false -p=${MAKE_JOBS} -.if empty(DEBUG) -# by default omit symbol table, debug information and DWARF symbol table -MODGO_LDFLAGS += -s -w -.else +.if ! empty(DEBUG) MODGO_FLAGS += -x .endif
Re: Go default LDFLAGS behavior
On 2024/02/27 17:53, Igor Zornik wrote: > Hello, > > How are default LDFLAGS for Go ports applied considering they are set > after they're included into the build command? I don't see those options > in the output when running make and the resulting binary is in its > standard size. However when I relocate the flag settings into the upper > part of the script as in the provided diff, it works as expected and I > get greeted with a shrunk binary. I think the default settings are > skipped on the official build server too, because Go binaries on mirrors > are similarly large. > > Could anyone clue me in if this behavior is still correct and I'm just > misunderstanding something? I think your diff is correct. In ports we're fairly used to being able to add to variables at various points in the Makefile and have them still take effect because they're often not referenced until bsd.port.mk or bsd.port.arch.mk is included, but obviously that's not the case here, so I think this was a bug introduced when MODGO_LDFLAGS was introduced and -s -w was split off from MODGO_FLAGS. Unless there are objections I'll commit it, with a _MODGO_SYSTEM_VERSION bump to make sure that users get updated to new package versions when they use pkg_add -u (to avoid bumping REVISION separately in all go ports). > Index: go.port.mk > === > RCS file: /cvs/ports/lang/go/go.port.mk,v > retrieving revision 1.66 > diff -u -p -r1.66 go.port.mk > --- go.port.mk21 Feb 2024 12:28:57 - 1.66 > +++ go.port.mk27 Feb 2024 15:23:27 - > @@ -58,6 +58,11 @@ MODGO_LIST_CMD = ${MODGO_CMD} list ${MOD > MODGO_TEST_CMD = ${MODGO_CMD} test ${MODGO_FLAGS} ${MODGO_TEST_FLAGS} > MODGO_BINDIR ?= bin > +.if empty(DEBUG) > +# by default omit symbol table, debug information and DWARF symbol table > +MODGO_LDFLAGS += -s -w > +.endif > + > .if ! empty(MODGO_LDFLAGS) > MODGO_BUILD_CMD += -ldflags="${MODGO_LDFLAGS}" > MODGO_LIST_CMD +=-ldflags="${MODGO_LDFLAGS}" > @@ -111,10 +116,7 @@ CATEGORIES +=lang/go > MODGO_BUILD_TARGET = ${MODGO_BUILD_CMD} ${ALL_TARGET} > MODGO_FLAGS += -v -buildvcs=false -p=${MAKE_JOBS} > -.if empty(DEBUG) > -# by default omit symbol table, debug information and DWARF symbol table > -MODGO_LDFLAGS += -s -w > -.else > +.if ! empty(DEBUG) > MODGO_FLAGS += -x > .endif >
Re: Go default LDFLAGS behavior
On Wed, Feb 28, 2024 at 09:12:04AM +, Stuart Henderson wrote: > On 2024/02/27 17:53, Igor Zornik wrote: > > Hello, > > > > How are default LDFLAGS for Go ports applied considering they are set > > after they're included into the build command? I don't see those options > > in the output when running make and the resulting binary is in its > > standard size. However when I relocate the flag settings into the upper > > part of the script as in the provided diff, it works as expected and I > > get greeted with a shrunk binary. I think the default settings are > > skipped on the official build server too, because Go binaries on mirrors > > are similarly large. > > > > Could anyone clue me in if this behavior is still correct and I'm just > > misunderstanding something? > > I think your diff is correct. > > In ports we're fairly used to being able to add to variables at various > points in the Makefile and have them still take effect because they're > often not referenced until bsd.port.mk or bsd.port.arch.mk is included, > but obviously that's not the case here, so I think this was a bug > introduced when MODGO_LDFLAGS was introduced and -s -w was split > off from MODGO_FLAGS. I agree. > Unless there are objections I'll commit it, with a _MODGO_SYSTEM_VERSION > bump to make sure that users get updated to new package versions when > they use pkg_add -u (to avoid bumping REVISION separately in all go > ports). ok tb > > > Index: go.port.mk > > === > > RCS file: /cvs/ports/lang/go/go.port.mk,v > > retrieving revision 1.66 > > diff -u -p -r1.66 go.port.mk > > --- go.port.mk 21 Feb 2024 12:28:57 - 1.66 > > +++ go.port.mk 27 Feb 2024 15:23:27 - > > @@ -58,6 +58,11 @@ MODGO_LIST_CMD = ${MODGO_CMD} list ${MOD > > MODGO_TEST_CMD = ${MODGO_CMD} test ${MODGO_FLAGS} ${MODGO_TEST_FLAGS} > > MODGO_BINDIR ?=bin > > +.if empty(DEBUG) > > +# by default omit symbol table, debug information and DWARF symbol table > > +MODGO_LDFLAGS += -s -w > > +.endif > > + > > .if ! empty(MODGO_LDFLAGS) > > MODGO_BUILD_CMD += -ldflags="${MODGO_LDFLAGS}" > > MODGO_LIST_CMD += -ldflags="${MODGO_LDFLAGS}" > > @@ -111,10 +116,7 @@ CATEGORIES += lang/go > > MODGO_BUILD_TARGET = ${MODGO_BUILD_CMD} ${ALL_TARGET} > > MODGO_FLAGS += -v -buildvcs=false -p=${MAKE_JOBS} > > -.if empty(DEBUG) > > -# by default omit symbol table, debug information and DWARF symbol table > > -MODGO_LDFLAGS += -s -w > > -.else > > +.if ! empty(DEBUG) > > MODGO_FLAGS += -x > > .endif > > >