x86, realmode: explicitly set ENTRY in linker script
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
@@ -11,6 +11,7 @@ OUTPUT_FORMAT("elf32-i386") OUTPUT_ARCH(i386) +ENTRY(0x1000) SECTIONS {
Signature · 1 line
2.23.0.351.gc4317032e6-goog
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 to0x1000
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: 0x1000While 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
Signed-off-by Nick Desaulniers <[email protected]>--- arch/x86/realmode/rm/realmode.lds.S | 1 + 1 file changed, 1 insertion(+)arch/x86/realmode/rm/realmode.lds.S +1
-1@@ -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.
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 to0x1000Linking with ld.bfd shows the default entry is
0x1000:$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry Entry point address: 0x1000While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.
Signed-off-by Nick Desaulniers <[email protected]>--- arch/x86/realmode/rm/realmode.lds.S | 1 + 1 file changed, 1 insertion(+)arch/x86/realmode/rm/realmode.lds.S +1
-0@@ -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
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 to0x1000Linking with ld.bfd shows the default entry is
0x1000:$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry Entry point address: 0x1000While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.
Signed-off-by Nick Desaulniers <[email protected]>--- arch/x86/realmode/rm/realmode.lds.S | 1 + 1 file changed, 1 insertion(+)arch/x86/realmode/rm/realmode.lds.S +1
-1@@ -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
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
@@ -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
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 to0x1000Linking 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: 0x1000While 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 forENTRY(0x1000)but is happy with-e 0x1000arch/x86/realmode/rm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/realmode/rm/Makefile +1
-2@@ -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
Borislav Petkov
maintainerRe: [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 to0x1000Linking with ld.bfd shows the default entry is
0x1000:$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry Entry point address: 0x1000While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.
Signed-off-by Nick Desaulniers <[email protected]>---
Changes V1 -> V2:
* Use command line flag, rather than linker script, as ld.bfd produces a syntax error forENTRY(0x1000)but is happy with-e 0x1000arch/x86/realmode/rm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/realmode/rm/Makefile +0
-0
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-netiquetteRe: [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 to0x1000Linking with ld.bfd shows the default entry is
0x1000:$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry Entry point address: 0x1000While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.
Signed-off-by Nick Desaulniers <[email protected]>---
Changes V1 -> V2:
* Use command line flag, rather than linker script, as ld.bfd produces a syntax error forENTRY(0x1000)but is happy with-e 0x1000arch/x86/realmode/rm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/realmode/rm/Makefile +0
-0arch/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 -TSo 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
0x2000and 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
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 to0x1000Linking with ld.bfd shows the default entry is
0x1000:$ readelf -h arch/x86/realmode/rm/realmode.elf | grep Entry Entry point address: 0x1000While ld.lld is being pedantic, just set the entry point explicitly, instead of depending on the implicit default.
Signed-off-by Nick Desaulniers <[email protected]>---
Changes V1 -> V2:
* Use command line flag, rather than linker script, as ld.bfd produces a syntax error forENTRY(0x1000)but is happy with-e 0x1000arch/x86/realmode/rm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/realmode/rm/Makefile +0
-0arch/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 -TSo 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
0x2000and 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
Borislav Petkov
maintainerRe: [PATCH v2] x86, realmode: explicitly set entry via command line
In reply to Nick DesaulniersQuoted 3 lines · Nick Desaulniers
Thanks for the consideration Boris. So IIUC if the preceding sections are larger than
0x1000altogether, 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
0x1000for 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
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-netiquettePATCH 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
@@ -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
[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
@@ -11,6 +11,7 @@ OUTPUT_FORMAT("elf32-i386") OUTPUT_ARCH(i386) +ENTRY(pa_text_start) SECTIONS {
[tip: x86/boot] x86/realmode: Explicitly set entry point via ENTRY in linker script
In reply to Nick DesaulniersThe 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
@@ -11,6 +11,7 @@ OUTPUT_FORMAT("elf32-i386") OUTPUT_ARCH(i386) +ENTRY(pa_text_start) SECTIONS {