* Using a custom LDFLAG for all objects and binaries
@ 2020-05-10 13:35 Mahmood Naderan
2020-05-10 16:02 ` Randy Dunlap
0 siblings, 1 reply; 8+ messages in thread
From: Mahmood Naderan @ 2020-05-10 13:35 UTC (permalink / raw)
To: linux-kernel
Hi
I would like to modify the kernel makefile in a way to include
--emit-relocs for every file that is linked during the process of
kernel make.
I see
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
LDFLAGS_MODULE =
LDFLAGS_vmlinux =
...
But I don't know which one is the main. Should I put that option in
front of every LD* variable? Or it is possible to apply one variable
for every file that is linked?
Appreciate your help.
Regards,
Mahmood
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using a custom LDFLAG for all objects and binaries
2020-05-10 13:35 Using a custom LDFLAG for all objects and binaries Mahmood Naderan
@ 2020-05-10 16:02 ` Randy Dunlap
2020-05-10 17:13 ` Mahmood Naderan
0 siblings, 1 reply; 8+ messages in thread
From: Randy Dunlap @ 2020-05-10 16:02 UTC (permalink / raw)
To: Mahmood Naderan, linux-kernel
On 5/10/20 6:35 AM, Mahmood Naderan wrote:
> Hi
> I would like to modify the kernel makefile in a way to include
> --emit-relocs for every file that is linked during the process of
> kernel make.
> I see
>
> KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
> LDFLAGS_MODULE =
> LDFLAGS_vmlinux =
> ...
>
> But I don't know which one is the main. Should I put that option in
> front of every LD* variable? Or it is possible to apply one variable
> for every file that is linked?
> Appreciate your help.
>
>
> Regards,
> Mahmood
Hi,
Have you read Documentation/kbuild/makefiles.rst ?
LDFLAGS
Generic $(LD) options
Flags used for all invocations of the linker.
You could always build with V=1 to see all of the
command lines that are used in the build.
HTH.
--
~Randy
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using a custom LDFLAG for all objects and binaries
2020-05-10 16:02 ` Randy Dunlap
@ 2020-05-10 17:13 ` Mahmood Naderan
2020-05-10 17:50 ` Randy Dunlap
0 siblings, 1 reply; 8+ messages in thread
From: Mahmood Naderan @ 2020-05-10 17:13 UTC (permalink / raw)
To: Randy Dunlap; +Cc: linux-kernel
> Have you read Documentation/kbuild/makefiles.rst ?
>
> LDFLAGS
> Generic $(LD) options
>
> Flags used for all invocations of the linker.
What I see is this in Documentation/kbuild/makefiles.txt
LDFLAGS Generic $(LD) options
Flags used for all invocations of the linker.
Often specifying the emulation is sufficient.
Example:
#arch/s390/Makefile
LDFLAGS := -m elf_s390
Note: ldflags-y can be used to further customise
the flags used. See chapter 3.7.
I have two questions then:
1- Can I use that as a bash variable? Like "LDFLAGS=--emit-relocs make"
or
2- Editing arch/x86/Makefile with
KBUILD_LDFLAGS := -m --emit-relocs elf_$(UTS_MACHINE)
Thanks for your help.
Regards,
Mahmood
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using a custom LDFLAG for all objects and binaries
2020-05-10 17:13 ` Mahmood Naderan
@ 2020-05-10 17:50 ` Randy Dunlap
2020-05-10 19:04 ` Mahmood Naderan
0 siblings, 1 reply; 8+ messages in thread
From: Randy Dunlap @ 2020-05-10 17:50 UTC (permalink / raw)
To: Mahmood Naderan; +Cc: linux-kernel, linux-kbuild
On 5/10/20 10:13 AM, Mahmood Naderan wrote:
>> Have you read Documentation/kbuild/makefiles.rst ?
>>
>> LDFLAGS
>> Generic $(LD) options
>>
>> Flags used for all invocations of the linker.
>
>
> What I see is this in Documentation/kbuild/makefiles.txt
>
> LDFLAGS Generic $(LD) options
>
> Flags used for all invocations of the linker.
> Often specifying the emulation is sufficient.
>
> Example:
> #arch/s390/Makefile
> LDFLAGS := -m elf_s390
> Note: ldflags-y can be used to further customise
> the flags used. See chapter 3.7.
>
>
>
> I have two questions then:
> 1- Can I use that as a bash variable? Like "LDFLAGS=--emit-relocs make"
I don't know. You could experiment with it to see.
(again by using 'make V=1' to see the commands that are being used)
> or
> 2- Editing arch/x86/Makefile with
> KBUILD_LDFLAGS := -m --emit-relocs elf_$(UTS_MACHINE)
That should work.
> Thanks for your help.
It would be better to ask these questions on the linux-kbuild mailing list
(added now).
--
~Randy
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using a custom LDFLAG for all objects and binaries
2020-05-10 17:50 ` Randy Dunlap
@ 2020-05-10 19:04 ` Mahmood Naderan
2020-05-10 19:08 ` Randy Dunlap
0 siblings, 1 reply; 8+ messages in thread
From: Mahmood Naderan @ 2020-05-10 19:04 UTC (permalink / raw)
To: Randy Dunlap; +Cc: linux-kernel, linux-kbuild
> > or
> > 2- Editing arch/x86/Makefile with
> > KBUILD_LDFLAGS := -m --emit-relocs elf_$(UTS_MACHINE)
>
> That should work.
Seems not... I ran the following commands:
$ cp -v /boot/config-$(uname -r) .config
$ make menuconfig -> Exit -> Save
$ vim arch/x86/Makefile
KBUILD_LDFLAGS := -m --emit-relocs elf_$(UTS_MACHINE)
$ make V=1
This is the error that I get
make -f ./scripts/Makefile.build obj=usr need-builtin=1
/bin/bash ./usr/gen_initramfs_list.sh -l -d > usr/.initramfs_data.cpio.d
(cat /dev/null; ) > usr/modules.order
make -f ./scripts/Makefile.build obj=arch/x86 need-builtin=1
make -f ./scripts/Makefile.build obj=arch/x86/crypto need-builtin=1
make -f ./scripts/Makefile.build obj=arch/x86/crypto/sha1-mb need-builtin=
(cat /dev/null; echo kernel/arch/x86/crypto/sha1-mb/sha1-mb.ko;) >
arch/x86/crypto/sha1-mb/modules.order
ld -m --emit-relocs elf_x86_64 -r -o
arch/x86/crypto/sha1-mb/sha1-mb.o arch/x86/crypto/sha1-mb/sha1_mb.o
arch/x86/crypto/sha1-mb/sha1_mb_mgr_flush_avx2.o
arch/x86/crypto/sha1-mb/sha1_mb_mgr_init_avx2.o
arch/x86/crypto/sha1-mb/sha1_mb_mgr_submit_avx2.o
arch/x86/crypto/sha1-mb/sha1_x8_avx2.o
ld: unrecognised emulation mode: --emit-relocs
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu
i386linux elf_l1om elf_k1om i386pep i386pe
scripts/Makefile.build:516: recipe for target
'arch/x86/crypto/sha1-mb/sha1-mb.o' failed
make[3]: *** [arch/x86/crypto/sha1-mb/sha1-mb.o] Error 1
scripts/Makefile.build:544: recipe for target 'arch/x86/crypto/sha1-mb' failed
make[2]: *** [arch/x86/crypto/sha1-mb] Error 2
scripts/Makefile.build:544: recipe for target 'arch/x86/crypto' failed
make[1]: *** [arch/x86/crypto] Error 2
Makefile:1053: recipe for target 'arch/x86' failed
make: *** [arch/x86] Error 2
ORIGINAL QUESTION:
>Hi
>I would like to modify the kernel makefile in a way to include
>--emit-relocs for every file that is linked during the process of
>kernel make.
>I see
>
>KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
>LDFLAGS_MODULE =
>LDFLAGS_vmlinux =
>...
>
>But I don't know which one is the main. Should I put that option in
>front of every LD* variable? Or it is possible to apply one variable
>for every file that is linked?
>Appreciate your help.
>
Regards,
Mahmood
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using a custom LDFLAG for all objects and binaries
2020-05-10 19:04 ` Mahmood Naderan
@ 2020-05-10 19:08 ` Randy Dunlap
2020-05-10 19:53 ` Mahmood Naderan
0 siblings, 1 reply; 8+ messages in thread
From: Randy Dunlap @ 2020-05-10 19:08 UTC (permalink / raw)
To: Mahmood Naderan; +Cc: linux-kernel, linux-kbuild
On 5/10/20 12:04 PM, Mahmood Naderan wrote:
>>> or
>>> 2- Editing arch/x86/Makefile with
>>> KBUILD_LDFLAGS := -m --emit-relocs elf_$(UTS_MACHINE)
>>
>> That should work.
>
>
> Seems not... I ran the following commands:
>
> $ cp -v /boot/config-$(uname -r) .config
> $ make menuconfig -> Exit -> Save
> $ vim arch/x86/Makefile
> KBUILD_LDFLAGS := -m --emit-relocs elf_$(UTS_MACHINE)
> $ make V=1
OK, I suggest that you reorder the options like so:
KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) --emit-relocs
I.e., don't split -m and the machine type.
> This is the error that I get
>
> make -f ./scripts/Makefile.build obj=usr need-builtin=1
> /bin/bash ./usr/gen_initramfs_list.sh -l -d > usr/.initramfs_data.cpio.d
> (cat /dev/null; ) > usr/modules.order
> make -f ./scripts/Makefile.build obj=arch/x86 need-builtin=1
> make -f ./scripts/Makefile.build obj=arch/x86/crypto need-builtin=1
> make -f ./scripts/Makefile.build obj=arch/x86/crypto/sha1-mb need-builtin=
> (cat /dev/null; echo kernel/arch/x86/crypto/sha1-mb/sha1-mb.ko;) >
> arch/x86/crypto/sha1-mb/modules.order
> ld -m --emit-relocs elf_x86_64 -r -o
> arch/x86/crypto/sha1-mb/sha1-mb.o arch/x86/crypto/sha1-mb/sha1_mb.o
> arch/x86/crypto/sha1-mb/sha1_mb_mgr_flush_avx2.o
> arch/x86/crypto/sha1-mb/sha1_mb_mgr_init_avx2.o
> arch/x86/crypto/sha1-mb/sha1_mb_mgr_submit_avx2.o
> arch/x86/crypto/sha1-mb/sha1_x8_avx2.o
> ld: unrecognised emulation mode: --emit-relocs
> Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu
> i386linux elf_l1om elf_k1om i386pep i386pe
> scripts/Makefile.build:516: recipe for target
> 'arch/x86/crypto/sha1-mb/sha1-mb.o' failed
> make[3]: *** [arch/x86/crypto/sha1-mb/sha1-mb.o] Error 1
> scripts/Makefile.build:544: recipe for target 'arch/x86/crypto/sha1-mb' failed
> make[2]: *** [arch/x86/crypto/sha1-mb] Error 2
> scripts/Makefile.build:544: recipe for target 'arch/x86/crypto' failed
> make[1]: *** [arch/x86/crypto] Error 2
> Makefile:1053: recipe for target 'arch/x86' failed
> make: *** [arch/x86] Error 2
>
>
>
>
>
> ORIGINAL QUESTION:
>
>> Hi
>> I would like to modify the kernel makefile in a way to include
>> --emit-relocs for every file that is linked during the process of
>> kernel make.
>> I see
>>
>> KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
>> LDFLAGS_MODULE =
>> LDFLAGS_vmlinux =
>> ...
>>
>> But I don't know which one is the main. Should I put that option in
>> front of every LD* variable? Or it is possible to apply one variable
>> for every file that is linked?
>> Appreciate your help.
>>
>
>
> Regards,
> Mahmood
>
--
~Randy
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using a custom LDFLAG for all objects and binaries
2020-05-10 19:08 ` Randy Dunlap
@ 2020-05-10 19:53 ` Mahmood Naderan
2020-05-10 20:30 ` Randy Dunlap
0 siblings, 1 reply; 8+ messages in thread
From: Mahmood Naderan @ 2020-05-10 19:53 UTC (permalink / raw)
To: Randy Dunlap; +Cc: linux-kernel, linux-kbuild
>OK, I suggest that you reorder the options like so:
>
> KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) --emit-relocs
I did that. After
$ make V=1
$ sudo make modules_install V=1
$ sudo make install
I grepped for "emit-relocs" in the log and saw many instances such as
gcc -Wp,-MD,drivers/rtc/.rtc-ds1305.o.d -nostdinc -isystem
/usr/lib/gcc/x86_64-linux-gnu/5/include -I./arch/x86/include
-I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi
-I./arch/x86/include/generated/uapi -I./include/uapi
-I./include/generated/uapi -include ./include/linux/kconfig.h -include
./include/linux/compiler_types.h -D__KERNEL__ -Wall -Wundef
-Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common
-fshort-wchar -Werror-implicit-function-declaration
-Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2
-mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387
-mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup
-mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time
-DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1
-DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1
-DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1
-DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1
-pipe -Wno-sign-compare -fno-asynchronous-unwind-tables
-mindirect-branch=thunk-extern -mindirect-branch-register
-fno-jump-tables -fno-delete-null-pointer-checks -O2
--param=allow-store-data-races=0 -Wframe-larger-than=1024
-fstack-protector-strong -Wno-unused-but-set-variable
-fno-omit-frame-pointer -fno-optimize-sibling-calls
-fno-var-tracking-assignments -g -gdwarf-4 -pg -mrecord-mcount
-mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement
-Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants
-fmerge-constants -fno-stack-check -fconserve-stack
-Werror=implicit-int -Werror=strict-prototypes -Werror=date-time
-Werror=incompatible-pointer-types -Werror=designated-init -DMODULE
-DKBUILD_BASENAME='"rtc_ds1305"' -DKBUILD_MODNAME='"rtc_ds1305"' -c -o
drivers/rtc/rtc-ds1305.o drivers/rtc/rtc-ds1305.c
./tools/objtool/objtool check --module --retpoline
"drivers/scsi/aacraid/dpcsup.o";
OR
ld -r -m elf_x86_64 --emit-relocs -z max-page-size=0x200000 -T
./scripts/module-common.lds --build-id -o
sound/usb/line6/snd-usb-line6.ko sound/usb/line6/snd-usb-line6.o
sound/usb/line6/snd-usb-line6.mod.o ; true
I guess that all kernel modules are now use --emit-relocs.
I would like to be sure that libc and those files related to syscalls
are also using that.
I grepped for "libc.so" but it seems that there is no such match.
Did I miss something?
Regards,
Mahmood
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Using a custom LDFLAG for all objects and binaries
2020-05-10 19:53 ` Mahmood Naderan
@ 2020-05-10 20:30 ` Randy Dunlap
0 siblings, 0 replies; 8+ messages in thread
From: Randy Dunlap @ 2020-05-10 20:30 UTC (permalink / raw)
To: Mahmood Naderan; +Cc: linux-kernel, linux-kbuild
On 5/10/20 12:53 PM, Mahmood Naderan wrote:
>> OK, I suggest that you reorder the options like so:
>>
>> KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) --emit-relocs
>
>
> I did that. After
>
> $ make V=1
> $ sudo make modules_install V=1
> $ sudo make install
>
> I grepped for "emit-relocs" in the log and saw many instances such as
>
> gcc -Wp,-MD,drivers/rtc/.rtc-ds1305.o.d -nostdinc -isystem
> /usr/lib/gcc/x86_64-linux-gnu/5/include -I./arch/x86/include
> -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi
> -I./arch/x86/include/generated/uapi -I./include/uapi
> -I./include/generated/uapi -include ./include/linux/kconfig.h -include
> ./include/linux/compiler_types.h -D__KERNEL__ -Wall -Wundef
> -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common
> -fshort-wchar -Werror-implicit-function-declaration
> -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2
> -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387
> -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup
> -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time
> -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1
> -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1
> -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1
> -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1
> -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables
> -mindirect-branch=thunk-extern -mindirect-branch-register
> -fno-jump-tables -fno-delete-null-pointer-checks -O2
> --param=allow-store-data-races=0 -Wframe-larger-than=1024
> -fstack-protector-strong -Wno-unused-but-set-variable
> -fno-omit-frame-pointer -fno-optimize-sibling-calls
> -fno-var-tracking-assignments -g -gdwarf-4 -pg -mrecord-mcount
> -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement
> -Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants
> -fmerge-constants -fno-stack-check -fconserve-stack
> -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time
> -Werror=incompatible-pointer-types -Werror=designated-init -DMODULE
> -DKBUILD_BASENAME='"rtc_ds1305"' -DKBUILD_MODNAME='"rtc_ds1305"' -c -o
> drivers/rtc/rtc-ds1305.o drivers/rtc/rtc-ds1305.c
> ./tools/objtool/objtool check --module --retpoline
> "drivers/scsi/aacraid/dpcsup.o";
>
> OR
>
> ld -r -m elf_x86_64 --emit-relocs -z max-page-size=0x200000 -T
> ./scripts/module-common.lds --build-id -o
> sound/usb/line6/snd-usb-line6.ko sound/usb/line6/snd-usb-line6.o
> sound/usb/line6/snd-usb-line6.mod.o ; true
>
>
>
> I guess that all kernel modules are now use --emit-relocs.
> I would like to be sure that libc and those files related to syscalls
> are also using that.
>
> I grepped for "libc.so" but it seems that there is no such match.
> Did I miss something?
The kernel doesn't use libc...
--
~Randy
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-05-10 20:30 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-10 13:35 Using a custom LDFLAG for all objects and binaries Mahmood Naderan
2020-05-10 16:02 ` Randy Dunlap
2020-05-10 17:13 ` Mahmood Naderan
2020-05-10 17:50 ` Randy Dunlap
2020-05-10 19:04 ` Mahmood Naderan
2020-05-10 19:08 ` Randy Dunlap
2020-05-10 19:53 ` Mahmood Naderan
2020-05-10 20:30 ` Randy Dunlap
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.