{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/29296","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/29296/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/29296/comments","events_url":"https://api.github.com/repos/golang/go/issues/29296/events","html_url":"https://github.com/golang/go/issues/29296","id":391483985,"node_id":"MDU6SXNzdWUzOTE0ODM5ODU=","number":29296,"title":"cmd/cgo: probable cgo gcc linker issue \"undefined reference\"","user":{"login":"denisvolin","id":17250986,"node_id":"MDQ6VXNlcjE3MjUwOTg2","avatar_url":"https://avatars0.githubusercontent.com/u/17250986?v=4","gravatar_id":"","url":"https://api.github.com/users/denisvolin","html_url":"https://github.com/denisvolin","followers_url":"https://api.github.com/users/denisvolin/followers","following_url":"https://api.github.com/users/denisvolin/following{/other_user}","gists_url":"https://api.github.com/users/denisvolin/gists{/gist_id}","starred_url":"https://api.github.com/users/denisvolin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denisvolin/subscriptions","organizations_url":"https://api.github.com/users/denisvolin/orgs","repos_url":"https://api.github.com/users/denisvolin/repos","events_url":"https://api.github.com/users/denisvolin/events{/privacy}","received_events_url":"https://api.github.com/users/denisvolin/received_events","type":"User","site_admin":false},"labels":[{"id":357033853,"node_id":"MDU6TGFiZWwzNTcwMzM4NTM=","url":"https://api.github.com/repos/golang/go/labels/WaitingForInfo","name":"WaitingForInfo","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-12-16T16:42:03Z","updated_at":"2018-12-17T08:41:52Z","closed_at":null,"author_association":"NONE","body":"### What version of Go are you using: 1.11.4;\r\n### Does this issue reproduce with the latest release: yes;\r\n### What operating system and processor architecture are you using: \r\nGOARCH=\"amd64\"\r\nGOBIN=\"/home/{username}/Go/bin\"\r\nGOCACHE=\"/home/{username}/.cache/go-build\"\r\nGOEXE=\"\"\r\nGOFLAGS=\"\"\r\nGOHOSTARCH=\"amd64\"\r\nGOHOSTOS=\"linux\"\r\nGOOS=\"linux\"\r\nGOPATH=\"/home/{username}/Go\"\r\nGOPROXY=\"\"\r\nGORACE=\"\"\r\nGOROOT=\"/usr/local/go\"\r\nGOTMPDIR=\"\"\r\nGOTOOLDIR=\"/usr/local/go/pkg/tool/linux_amd64\"\r\nGCCGO=\"gccgo\"\r\nCC=\"gcc\"\r\nCXX=\"g++\"\r\nCGO_ENABLED=\"1\"\r\nGOMOD=\"\"\r\nCGO_CFLAGS=\"-g -O2\"\r\nCGO_CPPFLAGS=\"\"\r\nCGO_CXXFLAGS=\"-g -O2\"\r\nCGO_FFLAGS=\"-g -O2\"\r\nCGO_LDFLAGS=\"-g -O2\"\r\nPKG_CONFIG=\"pkg-config\"\r\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build393278239=/tmp/go-build -gno-record-gcc-switches\"\r\n\r\n(It's Ubuntu 18.04.1 LTS)\r\n\r\n### What did you do:\r\nI'm building a cgo wrapper around some library and encounter probably a gcc linker issue, but since cgo calls linker implicitly I have not figured out how to implement the known workaround: https://stackoverflow.com/questions/12272864/linker-error-on-linux-undefined-reference-to\r\n\r\nBasically, the issue is that if you put the libraries after the object in the command line, the gcc ``linker may decide that it needs nothing from a particular library at the stage of the link where it scans the library, and then it won't rescan the library later after it finds some undefined symbols in the object files´´.\r\n\r\nAnd this situation happens only with a single symbol from the library. \r\n\r\nThe package that I'm building has both cgo pseudo-directives: CFLAGS -I and LDFLAGS -L for both amd64 and 386 architectures supported by the library being wrapped.\r\n\r\nOther symbols works just fine.\r\n\r\nUPD: More over if I create a new package dedicated to that single one symbol, it still reports the\r\nvery same issue.\r\n\r\nUPD: nm -g lib{library name}.so confirms the symbol is present.\r\n\r\nUPD: compiled a separate buffer shared library which is supposed to be proxying the symbol wrapping it under the new name; gcc compiled it just fine; no questions asked; then I've added -I, -L and -l flags to the original go (cgo) package and rerouted the call to use proxy; same failure it still argues about the undefined reference to the original (wrapped) symbol; nm -D libwrapper.so perfectly fine reports presence of both symbols.\r\n\r\n### What did you expect to see?\r\nEhm.. nothing... Successful building output.\r\n\r\n### What did you see instead?\r\nThe error output says:\r\n/tmp/go-build067792519/b001/_x030.o: In function `_cgo_742289945843_Cfunc_{symbol name}':\r\n/tmp/go-build/cgo-gcc-prolog:44: undefined reference to `{symbol name}'\r\ncollect2: error: ld returned 1 exit status\r\n"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/447764264","html_url":"https://github.com/golang/go/issues/29296#issuecomment-447764264","issue_url":"https://api.github.com/repos/golang/go/issues/29296","id":447764264,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0Nzc2NDI2NA==","user":{"login":"denisvolin","id":17250986,"node_id":"MDQ6VXNlcjE3MjUwOTg2","avatar_url":"https://avatars0.githubusercontent.com/u/17250986?v=4","gravatar_id":"","url":"https://api.github.com/users/denisvolin","html_url":"https://github.com/denisvolin","followers_url":"https://api.github.com/users/denisvolin/followers","following_url":"https://api.github.com/users/denisvolin/following{/other_user}","gists_url":"https://api.github.com/users/denisvolin/gists{/gist_id}","starred_url":"https://api.github.com/users/denisvolin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denisvolin/subscriptions","organizations_url":"https://api.github.com/users/denisvolin/orgs","repos_url":"https://api.github.com/users/denisvolin/repos","events_url":"https://api.github.com/users/denisvolin/events{/privacy}","received_events_url":"https://api.github.com/users/denisvolin/received_events","type":"User","site_admin":false},"created_at":"2018-12-17T08:41:52Z","updated_at":"2018-12-17T08:41:52Z","author_association":"NONE","body":"So, the question is: how can I redefine the linker arguments for building the code?"}}
{"actor":{"display_login":"denisvolin"}}