Re: Using a custom LDFLAG for all objects and binaries

From: Randy Dunlap
Date: Sun May 10 2020 - 16:30:58 EST


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