Skip to contentSkip to conversation

x86, realmode: explicitly set ENTRY in linker script

PATCH Superseded Nick Desaulniers 6 participants 13 messages Sep 23, 2019 – Oct 1, 2019 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, realmode: explicitly set ENTRY in linker script

Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.

---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/x86/realmode/rm/realmode.lds.S +1 -0
index 3bb980800c58..2034f5f79bff 100644
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(0x1000)
 
 SECTIONS
 {
Signature · 1 line
2.23.0.351.gc4317032e6-goog
#1 lore raw
Quoted 4 lines · Nick Desaulniers' via Clang Built Linux

Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Quoted 8 lines

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.

steps when linking with LLD on x86-64)

Quoted 24 lines
---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/x86/realmode/rm/realmode.lds.S +1 -1
index 3bb980800c58..2034f5f79bff 100644
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(0x1000)
 
 SECTIONS
 {
--

2.23.0.351.gc4317032e6-goog

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20190923222403.22956-1-ndesaulniers%40google.com.

#2 lore raw
In reply to Nick Desaulniers
Quoted 31 lines · Nick Desaulniers' via Clang Built Linux

Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.

---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/x86/realmode/rm/realmode.lds.S +1 -0
index 3bb980800c58..2034f5f79bff 100644
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(0x1000)
 
 SECTIONS
 {
Signature · 1 line
2.23.0.351.gc4317032e6-goog

This appears to break ld.bfd?

ld:arch/x86/realmode/rm/realmode.lds:131: syntax error
make[5]: *** [../arch/x86/realmode/rm/Makefile:54: arch/x86/realmode/rm/realmode.elf] Error 1 make[4]: *** [../arch/x86/realmode/Makefile:20: arch/x86/realmode/rm/realmode.bin] Error 2 make[3]: *** [../scripts/Makefile.build:509: arch/x86/realmode] Error 2

Cheers,
Nathan

#3 lore raw
Quoted 36 lines · Nathan Chancellor
Quoted 29 lines · Nick Desaulniers' via Clang Built Linux

Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.

---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/x86/realmode/rm/realmode.lds.S +1 -1
index 3bb980800c58..2034f5f79bff 100644
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(0x1000)
 
 SECTIONS
 {
--
Quoted 2 lines

2.23.0.351.gc4317032e6-goog

This appears to break ld.bfd?

Quoted 4 lines

ld:arch/x86/realmode/rm/realmode.lds:131: syntax error
make[5]: *** [../arch/x86/realmode/rm/Makefile:54: arch/x86/realmode/rm/realmode.elf] Error 1 make[4]: *** [../arch/x86/realmode/Makefile:20: arch/x86/realmode/rm/realmode.bin] Error 2 make[3]: *** [../scripts/Makefile.build:509: arch/x86/realmode] Error 2

Thanks for testing. Strange, it seems that ld.bfd doesn't like it as an ENTRY in the linker script, but will accept -e <addr>. Not sure if that's a bug in ld.bfd, or if ld.lld should error as well?
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/simple-commands.html
v2 inbound.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#4 lore raw

PATCH v2 1/1 x86, realmode: explicitly set entry via command line

Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.

---
Changes V1 -> V2:
* Use command line flag, rather than linker script, as ld.bfd produces a syntax error for ENTRY(0x1000) but is happy with -e 0x1000

 arch/x86/realmode/rm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/realmode/rm/Makefile +1 -1
index f60501a384f9..338a00c5257f 100644
@@ -46,7 +46,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
 targets += realmode.lds
 $(obj)/realmode.lds: $(obj)/pasyms.h
 
-LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T
+LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -e 0x1000 -T
 CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj)
 
 targets += realmode.elf
Signature · 1 line
2.23.0.351.gc4317032e6-goog
#5 lore raw

Re: [PATCH v2] x86, realmode: explicitly set entry via command line

Quoted 5 lines · Nick Desaulniers

Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

Quoted 8 lines
$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.

I meant to pick up Sedat's reported by tag:

Quoted 24 lines

---
Changes V1 -> V2:
* Use command line flag, rather than linker script, as ld.bfd produces a syntax error for ENTRY(0x1000) but is happy with -e 0x1000

 arch/x86/realmode/rm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/realmode/rm/Makefile +1 -2
index f60501a384f9..338a00c5257f 100644
@@ -46,7 +46,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
 targets += realmode.lds
 $(obj)/realmode.lds: $(obj)/pasyms.h
 
-LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T
+LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -e 0x1000 -T
 CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj)
 
 targets += realmode.elf
--

2.23.0.351.gc4317032e6-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer
#6 lore raw

Re: [PATCH v2] x86, realmode: explicitly set entry via command line

In reply to Nick Desaulniers

+ some more people who did the unified realmode thing.

Quoted 25 lines · Nick Desaulniers

Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.

---
Changes V1 -> V2:
* Use command line flag, rather than linker script, as ld.bfd produces a syntax error for ENTRY(0x1000) but is happy with -e 0x1000

 arch/x86/realmode/rm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/realmode/rm/Makefile +0 -0
index f60501a384f9..338a00c5257f 100644

arch/x86/realmode/rm/Makefile $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE · line 49

Quoted 5 lines
arch/x86/realmode/rm/Makefile +1 -1
@@ -46,7 +46,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
 targets += realmode.lds
 $(obj)/realmode.lds: $(obj)/pasyms.h
 
-LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T
+LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -e 0x1000 -T

So looking at arch/x86/realmode/rm/realmode.lds.S: what's stopping people from adding more sections before the first

. = ALIGN(PAGE_SIZE);

which, with enough bytes to go above the first 4K, would cause that alignment to go to 0x2000 and then your hardcoded address would be wrong, all of a sudden.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#7 lore raw

Re: [PATCH v2] x86, realmode: explicitly set entry via command line

+ Fangrui, Peter, Rui, George (LLD)

Quoted 38 lines · Borislav Petkov

+ some more people who did the unified realmode thing.

Quoted 25 lines · Nick Desaulniers

Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.

---
Changes V1 -> V2:
* Use command line flag, rather than linker script, as ld.bfd produces a syntax error for ENTRY(0x1000) but is happy with -e 0x1000

 arch/x86/realmode/rm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/realmode/rm/Makefile +0 -0
index f60501a384f9..338a00c5257f 100644

arch/x86/realmode/rm/Makefile $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE · line 49

Quoted 5 lines
arch/x86/realmode/rm/Makefile +1 -1
@@ -46,7 +46,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
 targets += realmode.lds
 $(obj)/realmode.lds: $(obj)/pasyms.h
 
-LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T
+LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -e 0x1000 -T

So looking at arch/x86/realmode/rm/realmode.lds.S: what's stopping people from adding more sections before the first

Quoted 5 lines

. = ALIGN(PAGE_SIZE);

which, with enough bytes to go above the first 4K, would cause that alignment to go to 0x2000 and then your hardcoded address would be wrong, all of a sudden.

Thanks for the consideration Boris. So IIUC if the preceding sections are larger than 0x1000 altogether, setting the entry there will be wrong?

Currently, .text looks like it's currently at 0x1000 for a defconfig, and I assume that could move in the case I stated above?

$ readelf -S arch/x86/realmode/rm/realmode.elf | grep text
  [ 3] .text             PROGBITS        00001000 201000 000f51 00  AX
 0   0 4096
...

In that case, it seems that maybe I should set the ENTRY in the linker script as:

(quoted diff) +0 -0

b/arch/x86/realmode/rm/realmode.lds.S
index 3bb980800c58..64d135d1ee63 100644

arch/x86/realmode/rm/realmode.lds.S +1 -0
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(pa_text_start)
 
 SECTIONS
 {
Signature · 2 lines
Thanks,
~Nick Desaulniers
#8 lore raw

Re: [PATCH v2] x86, realmode: explicitly set entry via command line

________________________________________
From: Nick Desaulniers <[email protected]>
Sent: 25 September 2019 17:35
To: Borislav Petkov
Cc: H. Peter Anvin; Jarkko Sakkinen; Thomas Gleixner; Ingo Molnar; clang-built-linux; maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT); Tri Vo; Masahiro Yamada; Rob Herring; George Rimar; LKML; Fangrui Song; Peter Smith; Rui Ueyama
Subject: Re: [PATCH v2] x86, realmode: explicitly set entry via command line

+ Fangrui, Peter, Rui, George (LLD)

Quoted 38 lines · Borislav Petkov

+ some more people who did the unified realmode thing.

Quoted 25 lines · Nick Desaulniers

Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.

---
Changes V1 -> V2:
* Use command line flag, rather than linker script, as ld.bfd produces a syntax error for ENTRY(0x1000) but is happy with -e 0x1000

 arch/x86/realmode/rm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/realmode/rm/Makefile +0 -0
index f60501a384f9..338a00c5257f 100644

arch/x86/realmode/rm/Makefile $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE · line 49

Quoted 5 lines
arch/x86/realmode/rm/Makefile +1 -1
@@ -46,7 +46,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
 targets += realmode.lds
 $(obj)/realmode.lds: $(obj)/pasyms.h
 
-LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T
+LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -e 0x1000 -T

So looking at arch/x86/realmode/rm/realmode.lds.S: what's stopping people from adding more sections before the first

Quoted 5 lines

. = ALIGN(PAGE_SIZE);

which, with enough bytes to go above the first 4K, would cause that alignment to go to 0x2000 and then your hardcoded address would be wrong, all of a sudden.

Thanks for the consideration Boris. So IIUC if the preceding sections are larger than 0x1000 altogether, setting the entry there will be wrong?

Currently, .text looks like it's currently at 0x1000 for a defconfig, and I assume that could move in the case I stated above?

$ readelf -S arch/x86/realmode/rm/realmode.elf | grep text
  [ 3] .text             PROGBITS        00001000 201000 000f51 00  AX
 0   0 4096
...

In that case, it seems that maybe I should set the ENTRY in the linker script as:

(quoted diff) +0 -0

b/arch/x86/realmode/rm/realmode.lds.S
index 3bb980800c58..64d135d1ee63 100644

arch/x86/realmode/rm/realmode.lds.S +1 -0
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(pa_text_start)
 
 SECTIONS
 {

--
Thanks,
~Nick Desaulniers

If I've understood the thread correctly, sorry jumping in late.
- LLD will set the entry point to the start of the .text section in absence of any of the other ways to communicate an entry point. It gives a warning in this case.
- Setting the entry point to an address that is the current start of the .text section silences the warning, but is potentially fragile.

I think LLD is on balance right to give a warning as in many cases the start of the .text section is not going to coincide with the desired entry point.

I recommend doing this via using a symbol defined at the entry point, for example Nick's last suggestion. This will be most resistant to changes such as the .text section changing address or the entry point isn't first in the .text section.

Peter

maintainer
#9 lore raw

Re: [PATCH v2] x86, realmode: explicitly set entry via command line

In reply to Nick Desaulniers
Quoted 3 lines · Nick Desaulniers

Thanks for the consideration Boris. So IIUC if the preceding sections are larger than 0x1000 altogether, setting the entry there will be wrong?

Well, I spent some time this morning grepping to find out whether PA 0x1000 was magical but didn't find anything. Perhaps hpa can refresh my memory...

Quoted 2 lines

Currently, .text looks like it's currently at 0x1000 for a defconfig, and I assume that could move in the case I stated above?

Yes, I think we shouldn't hardcode.

Quoted 13 lines
$ readelf -S arch/x86/realmode/rm/realmode.elf | grep text
  [ 3] .text             PROGBITS        00001000 201000 000f51 00  AX
 0   0 4096
...

In that case, it seems that maybe I should set the ENTRY in the linker script as:

arch/x86/realmode/rm/realmode.lds.S +0 -0
index 3bb980800c58..64d135d1ee63 100644

arch/x86/realmode/rm/realmode.lds.S line 14

Quoted 4 lines
arch/x86/realmode/rm/realmode.lds.S +1 -0
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(pa_text_start)

Well, looking at arch/x86/boot/setup.ld, it does do:

ENTRY(_start)

for the global _start symbol in .../boot/header.S.

So you doing the respective thing in that linker script would make sense...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#10 lore raw

PATCH v3 1/1 x86, realmode: explicitly set entry via ENTRY in linker script

Linking with ld.lld via $ make LD=ld.lld produces the warning:
ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default. The symbol pa_text_start refers to the start of the .text section, which may not be at 0x1000 if the preceding sections listed in arch/x86/realmode/rm/realmode.lds.S were large enough. This matches behavior in arch/x86/boot/setup.ld.

---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/x86/realmode/rm/realmode.lds.S +1 -0
index 3bb980800c58..64d135d1ee63 100644
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(pa_text_start)
 
 SECTIONS
 {
Signature · 1 line
2.23.0.351.gc4317032e6-goog
#11 lore raw

[tip: x86/boot] x86/realmode: Explicitly set entry point via ENTRY in linker script

The following commit has been merged into the x86/boot branch of tip:

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     3f5f909bc331a7ff9120b11c8e0e320d60b01c89
Gitweb:        https://git.kernel.org/tip/3f5f909bc331a7ff9120b11c8e0e320d60b01c89
Author:        Nick Desaulniers <[email protected]>
AuthorDate:    Wed, 25 Sep 2019 11:09:06 -07:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 01 Oct 2019 12:17:58 +02:00

x86/realmode: Explicitly set entry point via ENTRY in linker script

Linking with ld.lld via

$ make LD=ld.lld

produces the warning:

ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default. The symbol pa_text_start refers to the start of the .text section, which may not be at 0x1000 if the preceding sections listed in arch/x86/realmode/rm/realmode.lds.S were large enough. This matches behavior in arch/x86/boot/setup.ld.

---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/x86/realmode/rm/realmode.lds.S +1 -0
index 3bb9808..64d135d 100644
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(pa_text_start)
 
 SECTIONS
 {
#12 lore raw

[tip: x86/boot] x86/realmode: Explicitly set entry point via ENTRY in linker script

In reply to Nick Desaulniers
The following commit has been merged into the x86/boot branch of tip:

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     6a181e333954a26f46596b36f82abd14743570fd
Gitweb:        https://git.kernel.org/tip/6a181e333954a26f46596b36f82abd14743570fd
Author:        Nick Desaulniers <[email protected]>
AuthorDate:    Wed, 25 Sep 2019 11:09:06 -07:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 01 Oct 2019 22:13:17 +02:00

x86/realmode: Explicitly set entry point via ENTRY in linker script

Linking with ld.lld via

$ make LD=ld.lld

produces the warning:

ld.lld: warning: cannot find entry symbol _start; defaulting to 0x1000

Linking with ld.bfd shows the default entry is 0x1000:

$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry
  Entry point address:               0x1000

While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default. The symbol pa_text_start refers to the start of the .text section, which may not be at 0x1000 if the preceding sections listed in arch/x86/realmode/rm/realmode.lds.S were large enough. This matches behavior in arch/x86/boot/setup.ld.

---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/x86/realmode/rm/realmode.lds.S +1 -0
index 3bb9808..64d135d 100644
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(pa_text_start)
 
 SECTIONS
 {