Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: Support buildmode=pie with internal linking on Linux 386 #47949

Open
subsr97 opened this issue Aug 25, 2021 · 0 comments
Open

cmd/link: Support buildmode=pie with internal linking on Linux 386 #47949

subsr97 opened this issue Aug 25, 2021 · 0 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@subsr97
Copy link

subsr97 commented Aug 25, 2021

What version of Go are you using (go version)?

$ go version
go version go1.17 linux/386

Does this issue reproduce with the latest release?

Yes, I suppose this is the latest stable version for 386.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="386"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_386"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
GO386="sse2"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build698535093=/tmp/go-build -gno-record-gcc-switches"
uname -a Output
$ uname -a
Linux XXXX 4.19.0-17-686-pae #1 SMP Debian 4.19.194-3 (2021-07-18) i686 GNU/Linux
cat /etc/os-release Output
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

What did you do?

Tried compiling a hello world program with buildmode=pie and -linkmode=internal on a 386 machine.

package main

import "fmt"

func main() {
	fmt.Println("Hello, world!")
}
go build -buildmode=pie -ldflags="-linkmode=internal"  -o hello_world_pie ./hello_world.go

What did you expect to see?

I expected the program to get compiled successfully with PIE and internal linking enabled.

What did you see instead?

Build fails with the following error:

# command-line-arguments
/usr/local/go/pkg/tool/linux_386/link: internal linking requested but external linking required: buildmode=pie

For context, as mentioned in #31343, building a program with PIE and internal linking works on amd64.

uname -a Output
Linux xxxx-yyyy 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/os-release Output
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

Build command:

go build -buildmode=pie -ldflags="-linkmode=internal" -o hello_world_pie hello_world.go

The compilation is successful, and I have ensured that both PIE and internal linking are enabled.

hardening-check ./hello_world_pie Output
./hello_world_pie:
 Position Independent Executable: yes
 Stack protected: no, not found!
 Fortify Source functions: unknown, no protectable libc functions used
 Read-only relocations: yes
 Immediate binding: no, not found!
 Stack clash protection: unknown, no -fstack-clash-protection instructions found
 Control flow integrity: unknown, no -fcf-protection instructions found!
objdump -p hello_world_pie Output
hello_world_pie:     file format elf64-x86-64

Program Header:
PHDR off 0x0000000000000040 vaddr 0x0000000000400040 paddr 0x0000000000400040 align 212
filesz 0x00000000000002a0 memsz 0x00000000000002a0 flags r--
INTERP off 0x0000000000000fe4 vaddr 0x0000000000400fe4 paddr 0x0000000000400fe4 align 2
0
filesz 0x000000000000001c memsz 0x000000000000001c flags r--
NOTE off 0x0000000000000f80 vaddr 0x0000000000400f80 paddr 0x0000000000400f80 align 22
filesz 0x0000000000000064 memsz 0x0000000000000064 flags r--
LOAD off 0x0000000000000000 vaddr 0x0000000000400000 paddr 0x0000000000400000 align 2
12
filesz 0x0000000000099b60 memsz 0x0000000000099b60 flags r-x
LOAD off 0x000000000009a000 vaddr 0x000000000049a000 paddr 0x000000000049a000 align 212
filesz 0x0000000000072c85 memsz 0x0000000000072c85 flags r--
LOAD off 0x000000000010d000 vaddr 0x000000000050d000 paddr 0x000000000050d000 align 2
12
filesz 0x0000000000086239 memsz 0x0000000000086239 flags rw-
RELRO off 0x000000000010d000 vaddr 0x000000000050d000 paddr 0x000000000050d000 align 212
filesz 0x0000000000086239 memsz 0x0000000000086239 flags ---
LOAD off 0x0000000000194000 vaddr 0x0000000000594000 paddr 0x0000000000594000 align 2
12
filesz 0x0000000000015a20 memsz 0x00000000000481c8 flags rw-
DYNAMIC off 0x0000000000194040 vaddr 0x0000000000594040 paddr 0x0000000000594040 align 23
filesz 0x00000000000000b0 memsz 0x00000000000000b0 flags rw-
TLS off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2
3
filesz 0x0000000000000000 memsz 0x0000000000000008 flags r--
STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 23
filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
0x65041580 off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2
3
filesz 0x0000000000000000 memsz 0x0000000000000000 flags --- 2a00

Dynamic Section:
HASH 0x000000000050c9e0
SYMTAB 0x000000000050ca00
SYMENT 0x0000000000000018
STRTAB 0x000000000050c9d8
STRSZ 0x0000000000000001
RELA 0x00000000004b87b0
RELASZ 0x0000000000054228
RELAENT 0x0000000000000018
PLTGOT 0x0000000000594020
DEBUG 0x0000000000000000

@subsr97 subsr97 changed the title cmd/link: Support buildmode=pie with internal linking on 386 cmd/link: Support buildmode=pie with internal linking on Linux 386 Aug 25, 2021
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 25, 2021
@toothrot toothrot added this to the Backlog milestone Aug 25, 2021
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Triage Backlog
Development

No branches or pull requests

3 participants