linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86, realmode: explicitly set ENTRY in linker script
@ 2019-09-23 22:24 Nick Desaulniers
  2019-09-24 17:30 ` Sedat Dilek
  2019-09-24 18:24 ` Nathan Chancellor
  0 siblings, 2 replies; 13+ messages in thread
From: Nick Desaulniers @ 2019-09-23 22:24 UTC (permalink / raw)
  To: tglx, mingo, bp
  Cc: clang-built-linux, Nick Desaulniers, H. Peter Anvin, x86, linux-kernel

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.

Link: https://github.com/ClangBuiltLinux/linux/issues/216
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/realmode/rm/realmode.lds.S b/arch/x86/realmode/rm/realmode.lds.S
index 3bb980800c58..2034f5f79bff 100644
--- a/arch/x86/realmode/rm/realmode.lds.S
+++ b/arch/x86/realmode/rm/realmode.lds.S
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(0x1000)
 
 SECTIONS
 {
-- 
2.23.0.351.gc4317032e6-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] x86, realmode: explicitly set ENTRY in linker script
  2019-09-23 22:24 [PATCH] x86, realmode: explicitly set ENTRY in linker script Nick Desaulniers
@ 2019-09-24 17:30 ` Sedat Dilek
  2019-09-24 18:24 ` Nathan Chancellor
  1 sibling, 0 replies; 13+ messages in thread
From: Sedat Dilek @ 2019-09-24 17:30 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: tglx, mingo, bp, Clang-Built-Linux ML, H. Peter Anvin, x86, linux-kernel

On Tue, Sep 24, 2019 at 12:24 AM 'Nick Desaulniers' via Clang Built
Linux <clang-built-linux@googlegroups.com> wrote:
>
> 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.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/216

Reported-by: Sedat Dilek <sedat.dilek@gmail.com> (seen on my first
steps when linking with LLD on x86-64)

> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  arch/x86/realmode/rm/realmode.lds.S | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/arch/x86/realmode/rm/realmode.lds.S b/arch/x86/realmode/rm/realmode.lds.S
> index 3bb980800c58..2034f5f79bff 100644
> --- a/arch/x86/realmode/rm/realmode.lds.S
> +++ b/arch/x86/realmode/rm/realmode.lds.S
> @@ -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 clang-built-linux+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20190923222403.22956-1-ndesaulniers%40google.com.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] x86, realmode: explicitly set ENTRY in linker script
  2019-09-23 22:24 [PATCH] x86, realmode: explicitly set ENTRY in linker script Nick Desaulniers
  2019-09-24 17:30 ` Sedat Dilek
@ 2019-09-24 18:24 ` Nathan Chancellor
  2019-09-24 18:32   ` Nick Desaulniers
  1 sibling, 1 reply; 13+ messages in thread
From: Nathan Chancellor @ 2019-09-24 18:24 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: tglx, mingo, bp, clang-built-linux, H. Peter Anvin, x86, linux-kernel

On Mon, Sep 23, 2019 at 03:24:02PM -0700, 'Nick Desaulniers' via Clang Built Linux wrote:
> 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.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/216
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>  arch/x86/realmode/rm/realmode.lds.S | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/x86/realmode/rm/realmode.lds.S b/arch/x86/realmode/rm/realmode.lds.S
> index 3bb980800c58..2034f5f79bff 100644
> --- a/arch/x86/realmode/rm/realmode.lds.S
> +++ b/arch/x86/realmode/rm/realmode.lds.S
> @@ -11,6 +11,7 @@
>  
>  OUTPUT_FORMAT("elf32-i386")
>  OUTPUT_ARCH(i386)
> +ENTRY(0x1000)
>  
>  SECTIONS
>  {
> -- 
> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] x86, realmode: explicitly set ENTRY in linker script
  2019-09-24 18:24 ` Nathan Chancellor
@ 2019-09-24 18:32   ` Nick Desaulniers
  2019-09-24 19:33     ` [PATCH v2] x86, realmode: explicitly set entry via command line Nick Desaulniers
  0 siblings, 1 reply; 13+ messages in thread
From: Nick Desaulniers @ 2019-09-24 18:32 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, clang-built-linux,
	H. Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	LKML

On Tue, Sep 24, 2019 at 11:24 AM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> On Mon, Sep 23, 2019 at 03:24:02PM -0700, 'Nick Desaulniers' via Clang Built Linux wrote:
> > 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.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/216
> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > ---
> >  arch/x86/realmode/rm/realmode.lds.S | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/x86/realmode/rm/realmode.lds.S b/arch/x86/realmode/rm/realmode.lds.S
> > index 3bb980800c58..2034f5f79bff 100644
> > --- a/arch/x86/realmode/rm/realmode.lds.S
> > +++ b/arch/x86/realmode/rm/realmode.lds.S
> > @@ -11,6 +11,7 @@
> >
> >  OUTPUT_FORMAT("elf32-i386")
> >  OUTPUT_ARCH(i386)
> > +ENTRY(0x1000)
> >
> >  SECTIONS
> >  {
> > --
> > 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

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.
-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2] x86, realmode: explicitly set entry via command line
  2019-09-24 18:32   ` Nick Desaulniers
@ 2019-09-24 19:33     ` Nick Desaulniers
  2019-09-24 19:37       ` Nick Desaulniers
  2019-09-25 10:20       ` Borislav Petkov
  0 siblings, 2 replies; 13+ messages in thread
From: Nick Desaulniers @ 2019-09-24 19:33 UTC (permalink / raw)
  To: tglx, mingo, bp
  Cc: clang-built-linux, Nick Desaulniers, H. Peter Anvin, x86, Tri Vo,
	Masahiro Yamada, Rob Herring, George Rimar, linux-kernel

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.

Link: https://github.com/ClangBuiltLinux/linux/issues/216
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
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(-)

diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
index f60501a384f9..338a00c5257f 100644
--- a/arch/x86/realmode/rm/Makefile
+++ b/arch/x86/realmode/rm/Makefile
@@ -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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] x86, realmode: explicitly set entry via command line
  2019-09-24 19:33     ` [PATCH v2] x86, realmode: explicitly set entry via command line Nick Desaulniers
@ 2019-09-24 19:37       ` Nick Desaulniers
  2019-09-25 10:20       ` Borislav Petkov
  1 sibling, 0 replies; 13+ messages in thread
From: Nick Desaulniers @ 2019-09-24 19:37 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov
  Cc: clang-built-linux, H. Peter Anvin,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	Tri Vo, Masahiro Yamada, Rob Herring, George Rimar, LKML,
	Sedat Dilek

On Tue, Sep 24, 2019 at 12:33 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> 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.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/216
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

I meant to pick up Sedat's reported by tag:
Reported-by: Sedat Dilek <sedat.dilek@gmail.com>

> ---
> 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(-)
>
> diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
> index f60501a384f9..338a00c5257f 100644
> --- a/arch/x86/realmode/rm/Makefile
> +++ b/arch/x86/realmode/rm/Makefile
> @@ -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
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] x86, realmode: explicitly set entry via command line
  2019-09-24 19:33     ` [PATCH v2] x86, realmode: explicitly set entry via command line Nick Desaulniers
  2019-09-24 19:37       ` Nick Desaulniers
@ 2019-09-25 10:20       ` Borislav Petkov
  2019-09-25 16:35         ` Nick Desaulniers
  1 sibling, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2019-09-25 10:20 UTC (permalink / raw)
  To: Nick Desaulniers, H. Peter Anvin, Jarkko Sakkinen
  Cc: tglx, mingo, clang-built-linux, x86, Tri Vo, Masahiro Yamada,
	Rob Herring, George Rimar, linux-kernel

+ some more people who did the unified realmode thing.

On Tue, Sep 24, 2019 at 12:33:08PM -0700, Nick Desaulniers wrote:
> 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.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/216
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> 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(-)
> 
> diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
> index f60501a384f9..338a00c5257f 100644
> --- a/arch/x86/realmode/rm/Makefile
> +++ b/arch/x86/realmode/rm/Makefile
> @@ -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.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] x86, realmode: explicitly set entry via command line
  2019-09-25 10:20       ` Borislav Petkov
@ 2019-09-25 16:35         ` Nick Desaulniers
  2019-09-25 17:02           ` Peter Smith
  2019-09-25 17:10           ` Borislav Petkov
  0 siblings, 2 replies; 13+ messages in thread
From: Nick Desaulniers @ 2019-09-25 16:35 UTC (permalink / raw)
  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

+ Fangrui, Peter, Rui, George (LLD)

On Wed, Sep 25, 2019 at 3:20 AM Borislav Petkov <bp@alien8.de> wrote:
>
> + some more people who did the unified realmode thing.
>
> On Tue, Sep 24, 2019 at 12:33:08PM -0700, Nick Desaulniers wrote:
> > 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.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/216
> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > ---
> > 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(-)
> >
> > diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
> > index f60501a384f9..338a00c5257f 100644
> > --- a/arch/x86/realmode/rm/Makefile
> > +++ b/arch/x86/realmode/rm/Makefile
> > @@ -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.

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:
diff --git a/arch/x86/realmode/rm/realmode.lds.S
b/arch/x86/realmode/rm/realmode.lds.S
index 3bb980800c58..64d135d1ee63 100644
--- a/arch/x86/realmode/rm/realmode.lds.S
+++ b/arch/x86/realmode/rm/realmode.lds.S
@@ -11,6 +11,7 @@

 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(pa_text_start)

 SECTIONS
 {

-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] x86, realmode: explicitly set entry via command line
  2019-09-25 16:35         ` Nick Desaulniers
@ 2019-09-25 17:02           ` Peter Smith
  2019-09-25 17:10           ` Borislav Petkov
  1 sibling, 0 replies; 13+ messages in thread
From: Peter Smith @ 2019-09-25 17:02 UTC (permalink / raw)
  To: Nick Desaulniers, 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, Rui Ueyama, nd



________________________________________
From: Nick Desaulniers <ndesaulniers@google.com>
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)

On Wed, Sep 25, 2019 at 3:20 AM Borislav Petkov <bp@alien8.de> wrote:
>
> + some more people who did the unified realmode thing.
>
> On Tue, Sep 24, 2019 at 12:33:08PM -0700, Nick Desaulniers wrote:
> > 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.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/216
> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > ---
> > 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(-)
> >
> > diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
> > index f60501a384f9..338a00c5257f 100644
> > --- a/arch/x86/realmode/rm/Makefile
> > +++ b/arch/x86/realmode/rm/Makefile
> > @@ -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.

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:
diff --git a/arch/x86/realmode/rm/realmode.lds.S
b/arch/x86/realmode/rm/realmode.lds.S
index 3bb980800c58..64d135d1ee63 100644
--- a/arch/x86/realmode/rm/realmode.lds.S
+++ b/arch/x86/realmode/rm/realmode.lds.S
@@ -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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2] x86, realmode: explicitly set entry via command line
  2019-09-25 16:35         ` Nick Desaulniers
  2019-09-25 17:02           ` Peter Smith
@ 2019-09-25 17:10           ` Borislav Petkov
  2019-09-25 18:09             ` [PATCH v3] x86, realmode: explicitly set entry via ENTRY in linker script Nick Desaulniers
  1 sibling, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2019-09-25 17:10 UTC (permalink / raw)
  To: Nick Desaulniers
  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

On Wed, Sep 25, 2019 at 09:35:24AM -0700, Nick Desaulniers wrote:
> 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...

> 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.

> $ 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:
> diff --git a/arch/x86/realmode/rm/realmode.lds.S
> b/arch/x86/realmode/rm/realmode.lds.S
> index 3bb980800c58..64d135d1ee63 100644
> --- a/arch/x86/realmode/rm/realmode.lds.S
> +++ b/arch/x86/realmode/rm/realmode.lds.S
> @@ -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...

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3] x86, realmode: explicitly set entry via ENTRY in linker script
  2019-09-25 17:10           ` Borislav Petkov
@ 2019-09-25 18:09             ` Nick Desaulniers
  2019-10-01 10:37               ` [tip: x86/boot] x86/realmode: Explicitly set entry point " tip-bot2 for Nick Desaulniers
  2019-10-01 20:18               ` tip-bot2 for Nick Desaulniers
  0 siblings, 2 replies; 13+ messages in thread
From: Nick Desaulniers @ 2019-09-25 18:09 UTC (permalink / raw)
  To: tglx, mingo, bp
  Cc: clang-built-linux, maskray, grimar, ruiu, Nick Desaulniers,
	Peter Smith, H. Peter Anvin, x86, linux-kernel

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.

Link: https://github.com/ClangBuiltLinux/linux/issues/216
Suggested-by: Borislav Petkov <bp@alien8.de>
Suggested-by: Peter Smith <Peter.Smith@arm.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/realmode/rm/realmode.lds.S b/arch/x86/realmode/rm/realmode.lds.S
index 3bb980800c58..64d135d1ee63 100644
--- a/arch/x86/realmode/rm/realmode.lds.S
+++ b/arch/x86/realmode/rm/realmode.lds.S
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(pa_text_start)
 
 SECTIONS
 {
-- 
2.23.0.351.gc4317032e6-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip: x86/boot] x86/realmode: Explicitly set entry point via ENTRY in linker script
  2019-09-25 18:09             ` [PATCH v3] x86, realmode: explicitly set entry via ENTRY in linker script Nick Desaulniers
@ 2019-10-01 10:37               ` tip-bot2 for Nick Desaulniers
  2019-10-01 20:18               ` tip-bot2 for Nick Desaulniers
  1 sibling, 0 replies; 13+ messages in thread
From: tip-bot2 for Nick Desaulniers @ 2019-10-01 10:37 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Borislav Petkov, Peter Smith, Nick Desaulniers, Borislav Petkov,
	H. Peter Anvin, clang-built-linux, grimar, Ingo Molnar, maskray,
	ruiu, Thomas Gleixner, x86-ml, Ingo Molnar, linux-kernel

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 <ndesaulniers@google.com>
AuthorDate:    Wed, 25 Sep 2019 11:09:06 -07:00
Committer:     Borislav Petkov <bp@suse.de>
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.

Suggested-by: Borislav Petkov <bp@alien8.de>
Suggested-by: Peter Smith <Peter.Smith@arm.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: clang-built-linux@googlegroups.com
Cc: grimar@accesssoftek.com
Cc: Ingo Molnar <mingo@redhat.com>
Cc: maskray@google.com
Cc: ruiu@google.com
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190925180908.54260-1-ndesaulniers@google.com
Link: https://github.com/ClangBuiltLinux/linux/issues/216
---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/realmode/rm/realmode.lds.S b/arch/x86/realmode/rm/realmode.lds.S
index 3bb9808..64d135d 100644
--- a/arch/x86/realmode/rm/realmode.lds.S
+++ b/arch/x86/realmode/rm/realmode.lds.S
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(pa_text_start)
 
 SECTIONS
 {

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip: x86/boot] x86/realmode: Explicitly set entry point via ENTRY in linker script
  2019-09-25 18:09             ` [PATCH v3] x86, realmode: explicitly set entry via ENTRY in linker script Nick Desaulniers
  2019-10-01 10:37               ` [tip: x86/boot] x86/realmode: Explicitly set entry point " tip-bot2 for Nick Desaulniers
@ 2019-10-01 20:18               ` tip-bot2 for Nick Desaulniers
  1 sibling, 0 replies; 13+ messages in thread
From: tip-bot2 for Nick Desaulniers @ 2019-10-01 20:18 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sedat Dilek, Borislav Petkov, Peter Smith, Nick Desaulniers,
	Borislav Petkov, H. Peter Anvin, clang-built-linux, grimar,
	Ingo Molnar, maskray, ruiu, Thomas Gleixner, x86-ml, Ingo Molnar,
	linux-kernel

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 <ndesaulniers@google.com>
AuthorDate:    Wed, 25 Sep 2019 11:09:06 -07:00
Committer:     Borislav Petkov <bp@suse.de>
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.

Reported-by: Sedat Dilek <sedat.dilek@gmail.com>
Suggested-by: Borislav Petkov <bp@alien8.de>
Suggested-by: Peter Smith <Peter.Smith@arm.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: clang-built-linux@googlegroups.com
Cc: grimar@accesssoftek.com
Cc: Ingo Molnar <mingo@redhat.com>
Cc: maskray@google.com
Cc: ruiu@google.com
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190925180908.54260-1-ndesaulniers@google.com
Link: https://github.com/ClangBuiltLinux/linux/issues/216
---
 arch/x86/realmode/rm/realmode.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/realmode/rm/realmode.lds.S b/arch/x86/realmode/rm/realmode.lds.S
index 3bb9808..64d135d 100644
--- a/arch/x86/realmode/rm/realmode.lds.S
+++ b/arch/x86/realmode/rm/realmode.lds.S
@@ -11,6 +11,7 @@
 
 OUTPUT_FORMAT("elf32-i386")
 OUTPUT_ARCH(i386)
+ENTRY(pa_text_start)
 
 SECTIONS
 {

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-10-01 20:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-23 22:24 [PATCH] x86, realmode: explicitly set ENTRY in linker script Nick Desaulniers
2019-09-24 17:30 ` Sedat Dilek
2019-09-24 18:24 ` Nathan Chancellor
2019-09-24 18:32   ` Nick Desaulniers
2019-09-24 19:33     ` [PATCH v2] x86, realmode: explicitly set entry via command line Nick Desaulniers
2019-09-24 19:37       ` Nick Desaulniers
2019-09-25 10:20       ` Borislav Petkov
2019-09-25 16:35         ` Nick Desaulniers
2019-09-25 17:02           ` Peter Smith
2019-09-25 17:10           ` Borislav Petkov
2019-09-25 18:09             ` [PATCH v3] x86, realmode: explicitly set entry via ENTRY in linker script Nick Desaulniers
2019-10-01 10:37               ` [tip: x86/boot] x86/realmode: Explicitly set entry point " tip-bot2 for Nick Desaulniers
2019-10-01 20:18               ` tip-bot2 for Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).