Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

enable cgo for nvidia code #214

Merged
merged 1 commit into from
Nov 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/gobuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ mkdir -p "${SRCPATH}"
ln -s "${TOPWD}/ecs-init" "${SRCPATH}"
cd "${SRCPATH}/ecs-init"
if [[ "$1" == "dev" ]]; then
go build -tags 'development' -ldflags "${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build -tags 'development' -ldflags "${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe put the flags into another variable since we repeat later

Copy link
Member

Choose a reason for hiding this comment

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

I couldn't find anything to clarify the --unresolved-symbols=ignore-in-object-files portion of the flag, can you give some background on why these linker options are required for building with CGO specifically for enabling nvidia code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

vendor package for nvml APIs uses the cgo ldflags here -

// #cgo LDFLAGS: -ldl -Wl,--unresolved-symbols=ignore-in-object-files

Looks like only certain ldflags are whitelisted by default (golang/go#23749) and hence the build error as mentioned in the summary of this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, that explains it 👍

-o "${TOPWD}/amazon-ecs-init"
else
tags=""
if [[ "$1" != "" ]]; then
tags="-tags '$1'"
fi
CGO_ENABLED=0 go build -a ${tags} -x \
CGO_ENABLED=1 CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' go build -a ${tags} -x \
-ldflags "-s ${VERSION_FLAG} ${GIT_HASH_FLAG} ${GIT_DIRTY_FLAG}" \
-o "${TOPWD}/amazon-ecs-init"
fi
Expand Down