All of lore.kernel.org
 help / color / mirror / Atom feed
* Fix and simplify -z noreloc-overflow" linker check in arch/x86/boot/compressed/Makefile
@ 2019-03-12  9:13 Sedat Dilek
  2019-03-12 16:05 ` Masahiro Yamada
  0 siblings, 1 reply; 7+ messages in thread
From: Sedat Dilek @ 2019-03-12  9:13 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: linux-kbuild

Hi Masahiro Yamada,

do you have an idea how to fix this properly - as for example LLD
hasn't this option?
Speaking of the shell-line.
I mean use the method "call ld-option".

The below should be if $linker supports z noreloc-overflow then set
-pie together with --no-dynamic-linker.
AFAICS this is for x86-64-only?

Is it possible to simplify and have have one single line...?

KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)

[ arch/x86/boot/compressed/Makefile ]

KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
# Compressed kernel should be built as PIE since it may be loaded at any
# address by the bootloader.
ifeq ($(CONFIG_X86_32),y)
KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
else
# To build 64-bit compressed kernel as PIE, we disable relocation
# overflow check to avoid relocation overflow error with a new linker
# command-line option, -z noreloc-overflow.
KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
        && echo "-z noreloc-overflow -pie --no-dynamic-linker")
endif
LDFLAGS_vmlinux := -T

If you need more infos let me know.

Thanks.

Regards,
- Sedat -

Link: https://github.com/ClangBuiltLinux/linux/issues/411

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

* Re: Fix and simplify -z noreloc-overflow" linker check in arch/x86/boot/compressed/Makefile
  2019-03-12  9:13 Fix and simplify -z noreloc-overflow" linker check in arch/x86/boot/compressed/Makefile Sedat Dilek
@ 2019-03-12 16:05 ` Masahiro Yamada
  2019-03-13  8:51   ` Sedat Dilek
  0 siblings, 1 reply; 7+ messages in thread
From: Masahiro Yamada @ 2019-03-12 16:05 UTC (permalink / raw)
  To: Sedat Dilek; +Cc: Linux Kbuild mailing list

On Tue, Mar 12, 2019 at 6:13 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> Hi Masahiro Yamada,
>
> do you have an idea how to fix this properly - as for example LLD
> hasn't this option?
> Speaking of the shell-line.
> I mean use the method "call ld-option".
>
> The below should be if $linker supports z noreloc-overflow then set
> -pie together with --no-dynamic-linker.
> AFAICS this is for x86-64-only?
>
> Is it possible to simplify and have have one single line...?


Sorry, I do not understand.

Could you clarify what you want to achieve?


Thanks.






> KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
>
> [ arch/x86/boot/compressed/Makefile ]
>
> KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
> # Compressed kernel should be built as PIE since it may be loaded at any
> # address by the bootloader.
> ifeq ($(CONFIG_X86_32),y)
> KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
> else
> # To build 64-bit compressed kernel as PIE, we disable relocation
> # overflow check to avoid relocation overflow error with a new linker
> # command-line option, -z noreloc-overflow.
> KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
>         && echo "-z noreloc-overflow -pie --no-dynamic-linker")
> endif
> LDFLAGS_vmlinux := -T
>
> If you need more infos let me know.
>
> Thanks.
>
> Regards,
> - Sedat -
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/411



-- 
Best Regards
Masahiro Yamada

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

* Re: Fix and simplify -z noreloc-overflow" linker check in arch/x86/boot/compressed/Makefile
  2019-03-12 16:05 ` Masahiro Yamada
@ 2019-03-13  8:51   ` Sedat Dilek
  2019-03-18  9:45     ` Masahiro Yamada
  0 siblings, 1 reply; 7+ messages in thread
From: Sedat Dilek @ 2019-03-13  8:51 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Linux Kbuild mailing list

On Tue, Mar 12, 2019 at 5:06 PM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>
> On Tue, Mar 12, 2019 at 6:13 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
> >
> > Hi Masahiro Yamada,
> >
> > do you have an idea how to fix this properly - as for example LLD
> > hasn't this option?
> > Speaking of the shell-line.
> > I mean use the method "call ld-option".
> >
> > The below should be if $linker supports z noreloc-overflow then set
> > -pie together with --no-dynamic-linker.
> > AFAICS this is for x86-64-only?
> >
> > Is it possible to simplify and have have one single line...?
>
>
> Sorry, I do not understand.
>
> Could you clarify what you want to achieve?
>
>
> Thanks.
>
>
>
>
>
>
> > KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
> >
> > [ arch/x86/boot/compressed/Makefile ]
> >
> > KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
> > # Compressed kernel should be built as PIE since it may be loaded at any
> > # address by the bootloader.
> > ifeq ($(CONFIG_X86_32),y)
> > KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)

See below.

> > else
> > # To build 64-bit compressed kernel as PIE, we disable relocation
> > # overflow check to avoid relocation overflow error with a new linker
> > # command-line option, -z noreloc-overflow.

> > KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
> >         && echo "-z noreloc-overflow -pie --no-dynamic-linker")

First of all, I would like to have the "-z noreloc-overflow" checked
via "call ld-option".
Where I have problems is how to check the following, "-pie
--no-dynamic-linker" shall be set if "-z noreloc-overflow" is
available.
According to the comments, this is for the  CONFIG_X86_64 case.

ifeq ($(CONFIG_X86_64),y)
KBUILD_LDFLAGS += $(call ld-option, -z noreloc-overflow)
if z-noreloc-oevrflow-ld-option-is-available
KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
endif # z-noreloc-oevrflow-ld-option-is-available
endif # CONFIG_X86_64

As we have the 2nd check for the CONFIG_X86_32 case already, I asked
myself if it is possible to use it at one single place.

KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)

Is this now clearer?

Regards,
- Sedat -

> > endif
> > LDFLAGS_vmlinux := -T
> >
> > If you need more infos let me know.
> >
> > Thanks.
> >
> > Regards,
> > - Sedat -
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/411
>
>
>
> --
> Best Regards
> Masahiro Yamada

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

* Re: Fix and simplify -z noreloc-overflow" linker check in arch/x86/boot/compressed/Makefile
  2019-03-13  8:51   ` Sedat Dilek
@ 2019-03-18  9:45     ` Masahiro Yamada
  2019-03-18  9:49       ` Sedat Dilek
  2019-03-18 11:51       ` Sedat Dilek
  0 siblings, 2 replies; 7+ messages in thread
From: Masahiro Yamada @ 2019-03-18  9:45 UTC (permalink / raw)
  To: Sedat Dilek; +Cc: Linux Kbuild mailing list

Hi Sedat,


On Wed, Mar 13, 2019 at 5:52 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> On Tue, Mar 12, 2019 at 5:06 PM Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
> >
> > On Tue, Mar 12, 2019 at 6:13 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
> > >
> > > Hi Masahiro Yamada,
> > >
> > > do you have an idea how to fix this properly - as for example LLD
> > > hasn't this option?
> > > Speaking of the shell-line.
> > > I mean use the method "call ld-option".
> > >
> > > The below should be if $linker supports z noreloc-overflow then set
> > > -pie together with --no-dynamic-linker.
> > > AFAICS this is for x86-64-only?
> > >
> > > Is it possible to simplify and have have one single line...?
> >
> >
> > Sorry, I do not understand.
> >
> > Could you clarify what you want to achieve?
> >
> >
> > Thanks.
> >
> >
> >
> >
> >
> >
> > > KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
> > >
> > > [ arch/x86/boot/compressed/Makefile ]
> > >
> > > KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
> > > # Compressed kernel should be built as PIE since it may be loaded at any
> > > # address by the bootloader.
> > > ifeq ($(CONFIG_X86_32),y)
> > > KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
>
> See below.
>
> > > else
> > > # To build 64-bit compressed kernel as PIE, we disable relocation
> > > # overflow check to avoid relocation overflow error with a new linker
> > > # command-line option, -z noreloc-overflow.
>
> > > KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
> > >         && echo "-z noreloc-overflow -pie --no-dynamic-linker")
>
> First of all, I would like to have the "-z noreloc-overflow" checked
> via "call ld-option".
> Where I have problems is how to check the following, "-pie
> --no-dynamic-linker" shall be set if "-z noreloc-overflow" is
> available.
> According to the comments, this is for the  CONFIG_X86_64 case.
>
> ifeq ($(CONFIG_X86_64),y)
> KBUILD_LDFLAGS += $(call ld-option, -z noreloc-overflow)


Is this equivalent to
   $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" ... ?





> if z-noreloc-oevrflow-ld-option-is-available
> KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
> endif # z-noreloc-oevrflow-ld-option-is-available
> endif # CONFIG_X86_64
>
> As we have the 2nd check for the CONFIG_X86_32 case already, I asked
> myself if it is possible to use it at one single place.
>
> KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)


If you want to factor out the -pie --no-dynamic-linker tests,
the following may work.

It is not very clean...


ifeq ($(CONFIG_X86_64),y)
KBUILD_LDFLAGS = $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
       && echo "-z noreloc-overflow")
endif

ifneq ($(filter noreloc-overflow,$(KBUILD_LDFLAGS))$(CONFIG_X86_32),)
KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
endif




Perhaps, testing flags in Kconfig might make it a bit cleaner,
but I am not sure.


Masahiro


> Is this now clearer?
>
> Regards,
> - Sedat -
>
> > > endif
> > > LDFLAGS_vmlinux := -T
> > >
> > > If you need more infos let me know.
> > >
> > > Thanks.
> > >
> > > Regards,
> > > - Sedat -
> > >
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/411
> >
> >
> >
> > --
> > Best Regards
> > Masahiro Yamada



-- 
Best Regards
Masahiro Yamada

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

* Re: Fix and simplify -z noreloc-overflow" linker check in arch/x86/boot/compressed/Makefile
  2019-03-18  9:45     ` Masahiro Yamada
@ 2019-03-18  9:49       ` Sedat Dilek
  2019-03-18 11:51       ` Sedat Dilek
  1 sibling, 0 replies; 7+ messages in thread
From: Sedat Dilek @ 2019-03-18  9:49 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Linux Kbuild mailing list

On Mon, Mar 18, 2019 at 10:46 AM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>
> Hi Sedat,
>
>
> On Wed, Mar 13, 2019 at 5:52 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
> >
> > On Tue, Mar 12, 2019 at 5:06 PM Masahiro Yamada
> > <yamada.masahiro@socionext.com> wrote:
> > >
> > > On Tue, Mar 12, 2019 at 6:13 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
> > > >
> > > > Hi Masahiro Yamada,
> > > >
> > > > do you have an idea how to fix this properly - as for example LLD
> > > > hasn't this option?
> > > > Speaking of the shell-line.
> > > > I mean use the method "call ld-option".
> > > >
> > > > The below should be if $linker supports z noreloc-overflow then set
> > > > -pie together with --no-dynamic-linker.
> > > > AFAICS this is for x86-64-only?
> > > >
> > > > Is it possible to simplify and have have one single line...?
> > >
> > >
> > > Sorry, I do not understand.
> > >
> > > Could you clarify what you want to achieve?
> > >
> > >
> > > Thanks.
> > >
> > >
> > >
> > >
> > >
> > >
> > > > KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
> > > >
> > > > [ arch/x86/boot/compressed/Makefile ]
> > > >
> > > > KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
> > > > # Compressed kernel should be built as PIE since it may be loaded at any
> > > > # address by the bootloader.
> > > > ifeq ($(CONFIG_X86_32),y)
> > > > KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
> >
> > See below.
> >
> > > > else
> > > > # To build 64-bit compressed kernel as PIE, we disable relocation
> > > > # overflow check to avoid relocation overflow error with a new linker
> > > > # command-line option, -z noreloc-overflow.
> >
> > > > KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
> > > >         && echo "-z noreloc-overflow -pie --no-dynamic-linker")
> >
> > First of all, I would like to have the "-z noreloc-overflow" checked
> > via "call ld-option".
> > Where I have problems is how to check the following, "-pie
> > --no-dynamic-linker" shall be set if "-z noreloc-overflow" is
> > available.
> > According to the comments, this is for the  CONFIG_X86_64 case.
> >
> > ifeq ($(CONFIG_X86_64),y)
> > KBUILD_LDFLAGS += $(call ld-option, -z noreloc-overflow)
>
>
> Is this equivalent to
>    $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" ... ?
>
>
>
>
>
> > if z-noreloc-oevrflow-ld-option-is-available
> > KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
> > endif # z-noreloc-oevrflow-ld-option-is-available
> > endif # CONFIG_X86_64
> >
> > As we have the 2nd check for the CONFIG_X86_32 case already, I asked
> > myself if it is possible to use it at one single place.
> >
> > KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
>
>
> If you want to factor out the -pie --no-dynamic-linker tests,
> the following may work.
>
> It is not very clean...
>

Hehe.
Thanks for taking care!

- sed@ -

>
> ifeq ($(CONFIG_X86_64),y)
> KBUILD_LDFLAGS = $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
>        && echo "-z noreloc-overflow")
> endif
>
> ifneq ($(filter noreloc-overflow,$(KBUILD_LDFLAGS))$(CONFIG_X86_32),)
> KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
> endif
>
>
>
>
> Perhaps, testing flags in Kconfig might make it a bit cleaner,
> but I am not sure.
>
>
> Masahiro
>
>
> > Is this now clearer?
> >
> > Regards,
> > - Sedat -
> >
> > > > endif
> > > > LDFLAGS_vmlinux := -T
> > > >
> > > > If you need more infos let me know.
> > > >
> > > > Thanks.
> > > >
> > > > Regards,
> > > > - Sedat -
> > > >
> > > > Link: https://github.com/ClangBuiltLinux/linux/issues/411
> > >
> > >
> > >
> > > --
> > > Best Regards
> > > Masahiro Yamada
>
>
>
> --
> Best Regards
> Masahiro Yamada

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

* Re: Fix and simplify -z noreloc-overflow" linker check in arch/x86/boot/compressed/Makefile
  2019-03-18  9:45     ` Masahiro Yamada
  2019-03-18  9:49       ` Sedat Dilek
@ 2019-03-18 11:51       ` Sedat Dilek
  2019-03-19  0:53         ` Masahiro Yamada
  1 sibling, 1 reply; 7+ messages in thread
From: Sedat Dilek @ 2019-03-18 11:51 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Linux Kbuild mailing list

On Mon, Mar 18, 2019 at 10:46 AM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
[ ... ]
> > ifeq ($(CONFIG_X86_64),y)
> > KBUILD_LDFLAGS += $(call ld-option, -z noreloc-overflow)
>
>
> Is this equivalent to
>    $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" ... ?

I tried with BFD (option exists and is set) and LLD (option does not
exist, is not set).

You do not think it is equivalent?

- sed@ -

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

* Re: Fix and simplify -z noreloc-overflow" linker check in arch/x86/boot/compressed/Makefile
  2019-03-18 11:51       ` Sedat Dilek
@ 2019-03-19  0:53         ` Masahiro Yamada
  0 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2019-03-19  0:53 UTC (permalink / raw)
  To: Sedat Dilek; +Cc: Linux Kbuild mailing list

On Mon, Mar 18, 2019 at 8:51 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> On Mon, Mar 18, 2019 at 10:46 AM Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
> [ ... ]
> > > ifeq ($(CONFIG_X86_64),y)
> > > KBUILD_LDFLAGS += $(call ld-option, -z noreloc-overflow)
> >
> >
> > Is this equivalent to
> >    $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" ... ?
>
> I tried with BFD (option exists and is set) and LLD (option does not
> exist, is not set).
>
> You do not think it is equivalent?


How about BFD (option does not exist) ?

cc-option, ld-option, and friends
check whether the exit code is zero or not.


ld shows a warning for unsupported "-v ...",
but returns 0 somehow.

But, it correctly returns 1 for the other
unsupported options.

I do not know why.


$ ld -v
GNU ld (GNU Binutils for Ubuntu) 2.26.1
$ ld --help 2>&1 | grep -q "\-z noreloc-overflow"
$ echo $?
1
$ ld -z noreloc-overflow -v
ld: warning: -z noreloc-overflow ignored.
GNU ld (GNU Binutils for Ubuntu) 2.26.1
$ echo $?
0
$ ld -mmy-machine -v
ld: unrecognised emulation mode: my-machine
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu
i386linux elf_l1om elf_k1om i386pep i386pe
$ echo $?
1




-- 
Best Regards
Masahiro Yamada

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

end of thread, other threads:[~2019-03-19  0:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-12  9:13 Fix and simplify -z noreloc-overflow" linker check in arch/x86/boot/compressed/Makefile Sedat Dilek
2019-03-12 16:05 ` Masahiro Yamada
2019-03-13  8:51   ` Sedat Dilek
2019-03-18  9:45     ` Masahiro Yamada
2019-03-18  9:49       ` Sedat Dilek
2019-03-18 11:51       ` Sedat Dilek
2019-03-19  0:53         ` Masahiro Yamada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.