link order in executable

94 views
Skip to first unread message

Michael Stiller

unread,
Jan 24, 2020, 4:11:08 PM1/24/20
to golang-nuts
Hi,

playing around with tamago i noticed that if i compile with this command:

GO_EXTLINK_ENABLED=0 CGO_ENABLED=0 GOOS=tamago GOARM=6 GOARCH=arm \
${TAMAGO} build -ldflags "-v -T 0x00008000 -E _rt0_arm_tamago -R 0x1000" $@

The generated (elf) binary has the following symbols:

nm main | sort | head
00008000 T internal/cpu.Initialize
00008000 t runtime.text
00008144 T internal/cpu.processOptions
000087d4 T internal/cpu.indexByte
00008848 T type..hash.internal/cpu.CacheLinePad
00008858 T type..eq.internal/cpu.CacheLinePad
00008868 T type..hash.internal/cpu.arm
000088b0 T type..eq.internal/cpu.arm
000088ec T type..hash.internal/cpu.arm64
00008934 T type..eq.internal/cpu.arm64

What determines and is this configurable that internal/cpu.Initialize gets linked at 0x00008000?

What i want to achieve is, that the -E entry symbol gets linked first at 0x8000.

Thanks.

Best regards,

Michael

Ian Lance Taylor

unread,
Jan 24, 2020, 4:19:57 PM1/24/20
to Michael Stiller, golang-nuts
Nothing in particular determines that that symbol is a 0x8000. The -T
option says that the text segment will start at 0x8000. The Go linker
doesn't have any support for ordering the symbols in the text segment.
They just wind up being placed based on the order in which the linker
processes its inputs, which is unpredictable and subject to change.

The -E option sets the value stored in the ELF ehdr's e_entry field.

Ian

Michael Stiller

unread,
Jan 25, 2020, 4:31:26 AM1/25/20
to Ian Lance Taylor, golang-nuts
Thank you Ian.

Best regards,

Michael
Reply all
Reply to author
Forward
0 new messages