{"record":{"id":"8c6dfcdf5eaaed30","repo":"golang/go","slug":"invalid-linkmode-q","errorCode":null,"errorMessage":"invalid linkmode: %q","messagePattern":"invalid linkmode: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/ld/config.go","lineNumber":93,"sourceCode":"\tcase BuildModePlugin:\n\t\treturn \"plugin\"\n\t}\n\treturn fmt.Sprintf(\"BuildMode(%d)\", uint8(mode))\n}\n\n// LinkMode indicates whether an external linker is used for the final link.\ntype LinkMode uint8\n\nconst (\n\tLinkAuto LinkMode = iota\n\tLinkInternal\n\tLinkExternal\n)\n\nfunc (mode *LinkMode) Set(s string) error {\n\tswitch s {\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid linkmode: %q\", s)\n\tcase \"auto\":\n\t\t*mode = LinkAuto\n\tcase \"internal\":\n\t\t*mode = LinkInternal\n\tcase \"external\":\n\t\t*mode = LinkExternal\n\t}\n\treturn nil\n}\n\nfunc (mode *LinkMode) String() string {\n\tswitch *mode {\n\tcase LinkAuto:\n\t\treturn \"auto\"\n\tcase LinkInternal:\n\t\treturn \"internal\"\n\tcase LinkExternal:\n\t\treturn \"external\"","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/ld/config.go#L75-L111","documentation":"The Go linker's LinkMode.Set method rejects an unrecognized -linkmode flag value. LinkMode controls whether the internal or external linker is used for the final link step. Valid values are: auto (let the linker decide), internal (use Go's internal linker), and external (use the system's external linker such as gcc or clang).","triggerScenarios":"The flag.Value Set method is called by the flag parser with the -linkmode argument. If the string does not match 'auto', 'internal', or 'external', the default branch returns this error.","commonSituations":"Typo in linkmode name; using a linkmode value from documentation that has been renamed; passing the value through ldflags incorrectly; build scripts that construct ldflags dynamically with an unvalidated variable.","solutions":["Use one of the three valid values: auto, internal, or external","Check the flag is passed correctly: go build -ldflags='-linkmode=external'","If unsure which to use, omit the flag entirely (defaults to auto)","Validate the linkmode in build scripts before passing to the linker"],"exampleFix":"# before\ngo build -ldflags='-linkmode=pie' main.go\n\n# after\ngo build -ldflags='-linkmode=external' main.go","handlingStrategy":"validation","validationCode":"// Validate linkmode before passing to linker\nvar validLinkModes = map[string]bool{\n    \"auto\": true, \"internal\": true, \"external\": true,\n}\n\nfunc validateLinkMode(s string) error {\n    if !validLinkModes[s] {\n        return fmt.Errorf(\"invalid linkmode %q; valid: auto, internal, external\", s)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// Handle linkmode errors gracefully\nif err := linkMode.Set(s); err != nil {\n    fmt.Fprintf(os.Stderr, \"Error: %v\\nValid linkmodes: auto, internal, external\\n\", err)\n    os.Exit(1)\n}","preventionTips":["Valid linkmodes are only: auto, internal, external","When in doubt, omit -linkmode entirely — the default 'auto' is usually correct","External linking requires a C toolchain (gcc/clang) installed"],"tags":["linkmode","configuration","linker","go-toolchain","cli-flag"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}