From 6da2f8e139db62ac7ffe6882e0a03f4e8fabaf0c Mon Sep 17 00:00:00 2001 From: Regina König Date: Thu, 1 Jul 2021 10:04:35 +0200 Subject: Do some clean up --- debugging_demo/.gitignore | 4 + debugging_demo/ApplicationEntryPoint.o | Bin 22720 -> 0 bytes debugging_demo/BaseDebugPrintErrorLevelLib.o | Bin 4488 -> 0 bytes debugging_demo/BaseLib.o | Bin 380224 -> 0 bytes debugging_demo/BaseMemoryLib.o | Bin 104584 -> 0 bytes debugging_demo/BasePcdLibNull.o | Bin 62968 -> 0 bytes debugging_demo/BasePrintLib.o | Bin 66200 -> 0 bytes debugging_demo/Efi_Defs.o | Bin 37680 -> 0 bytes debugging_demo/GccBase.lds | 79 ++++++++++ debugging_demo/Makefile | 22 +-- debugging_demo/MemtestEfi.efi | Bin 2747 -> 0 bytes debugging_demo/MemtestEfi.o | Bin 20304 -> 0 bytes debugging_demo/OUTPUT/MemtestEfi.so | Bin 2118152 -> 0 bytes debugging_demo/UefiBootServicesTableLib.o | Bin 22880 -> 0 bytes debugging_demo/UefiDebugLibStdErr.o | Bin 52816 -> 0 bytes debugging_demo/UefiDevicePathLib2.o | Bin 373840 -> 0 bytes debugging_demo/UefiLib2.o | Bin 287376 -> 0 bytes debugging_demo/UefiMemoryAllocationLib.o | Bin 41272 -> 0 bytes debugging_demo/UefiRuntimeServicesTableLib.o | Bin 22080 -> 0 bytes efi_memtest/Makefile_orig | 214 --------------------------- efi_memtest/OUTPUT/MemtestEfi.lib | Bin 2568674 -> 2570594 bytes test_code/run.sh | 6 +- 22 files changed, 98 insertions(+), 227 deletions(-) create mode 100644 debugging_demo/.gitignore delete mode 100644 debugging_demo/ApplicationEntryPoint.o delete mode 100644 debugging_demo/BaseDebugPrintErrorLevelLib.o delete mode 100644 debugging_demo/BaseLib.o delete mode 100644 debugging_demo/BaseMemoryLib.o delete mode 100644 debugging_demo/BasePcdLibNull.o delete mode 100644 debugging_demo/BasePrintLib.o delete mode 100644 debugging_demo/Efi_Defs.o create mode 100644 debugging_demo/GccBase.lds delete mode 100755 debugging_demo/MemtestEfi.efi delete mode 100644 debugging_demo/MemtestEfi.o delete mode 100755 debugging_demo/OUTPUT/MemtestEfi.so delete mode 100644 debugging_demo/UefiBootServicesTableLib.o delete mode 100644 debugging_demo/UefiDebugLibStdErr.o delete mode 100644 debugging_demo/UefiDevicePathLib2.o delete mode 100644 debugging_demo/UefiLib2.o delete mode 100644 debugging_demo/UefiMemoryAllocationLib.o delete mode 100644 debugging_demo/UefiRuntimeServicesTableLib.o delete mode 100644 efi_memtest/Makefile_orig diff --git a/debugging_demo/.gitignore b/debugging_demo/.gitignore new file mode 100644 index 0000000..ee9b5b1 --- /dev/null +++ b/debugging_demo/.gitignore @@ -0,0 +1,4 @@ +*.o +*.so +*.efi +OUTPUT/ diff --git a/debugging_demo/ApplicationEntryPoint.o b/debugging_demo/ApplicationEntryPoint.o deleted file mode 100644 index 90c7d94..0000000 Binary files a/debugging_demo/ApplicationEntryPoint.o and /dev/null differ diff --git a/debugging_demo/BaseDebugPrintErrorLevelLib.o b/debugging_demo/BaseDebugPrintErrorLevelLib.o deleted file mode 100644 index 4a24065..0000000 Binary files a/debugging_demo/BaseDebugPrintErrorLevelLib.o and /dev/null differ diff --git a/debugging_demo/BaseLib.o b/debugging_demo/BaseLib.o deleted file mode 100644 index 1232d15..0000000 Binary files a/debugging_demo/BaseLib.o and /dev/null differ diff --git a/debugging_demo/BaseMemoryLib.o b/debugging_demo/BaseMemoryLib.o deleted file mode 100644 index 96e84da..0000000 Binary files a/debugging_demo/BaseMemoryLib.o and /dev/null differ diff --git a/debugging_demo/BasePcdLibNull.o b/debugging_demo/BasePcdLibNull.o deleted file mode 100644 index fb95c87..0000000 Binary files a/debugging_demo/BasePcdLibNull.o and /dev/null differ diff --git a/debugging_demo/BasePrintLib.o b/debugging_demo/BasePrintLib.o deleted file mode 100644 index 026f38a..0000000 Binary files a/debugging_demo/BasePrintLib.o and /dev/null differ diff --git a/debugging_demo/Efi_Defs.o b/debugging_demo/Efi_Defs.o deleted file mode 100644 index 551e68f..0000000 Binary files a/debugging_demo/Efi_Defs.o and /dev/null differ diff --git a/debugging_demo/GccBase.lds b/debugging_demo/GccBase.lds new file mode 100644 index 0000000..86d4eed --- /dev/null +++ b/debugging_demo/GccBase.lds @@ -0,0 +1,79 @@ +/** @file + + Unified linker script for GCC based builds + + Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2015, Linaro Ltd. All rights reserved.
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +SECTIONS { + + /* + * The PE/COFF binary consists of DOS and PE/COFF headers, and a sequence of + * section headers adding up to PECOFF_HEADER_SIZE bytes (which differs + * between 32-bit and 64-bit builds). The actual start of the .text section + * will be rounded up based on its actual alignment. + */ + . = PECOFF_HEADER_SIZE; + + .text : ALIGN(CONSTANT(COMMONPAGESIZE)) { + *(.text .text.* .stub .gnu.linkonce.t.*) + *(.rodata .rodata.* .gnu.linkonce.r.*) + *(.got .got.*) + + /* + * The contents of Efi_Defs.c files are mostly constant from the POV of the + * program, but most of it ends up in .data or .bss by default since few of + * the variable definitions that get emitted are declared as CONST. + * Unfortunately, we cannot pull it into the .text section entirely, since + * patchable PCDs are also emitted here, but we can at least move all of the + * emitted GUIDs here. + */ + *:Efi_Defs.obj(.data.g*Guid) + } + + /* + * The alignment of the .data section should be less than or equal to the + * alignment of the .text section. This ensures that the relative offset + * between these sections is the same in the ELF and the PE/COFF versions of + * this binary. + */ + .data ALIGN(ALIGNOF(.text)) : ALIGN(CONSTANT(COMMONPAGESIZE)) { + *(.data .data.* .gnu.linkonce.d.*) + *(.bss .bss.*) + } + + .eh_frame ALIGN(CONSTANT(COMMONPAGESIZE)) : { + KEEP (*(.eh_frame)) + } + + .rela (INFO) : { + *(.rela .rela.*) + } + + .hii : ALIGN(CONSTANT(COMMONPAGESIZE)) { + KEEP (*(.hii)) + } + + /* + * Retain the GNU build id but in a non-allocatable section so GenFw + * does not copy it into the PE/COFF image. + */ + .build-id (INFO) : { *(.note.gnu.build-id) } + + /DISCARD/ : { + *(.note.GNU-stack) + *(.gnu_debuglink) + *(.interp) + *(.dynsym) + *(.dynstr) + *(.dynamic) + *(.hash .gnu.hash) + *(.comment) + *(COMMON) + } +} diff --git a/debugging_demo/Makefile b/debugging_demo/Makefile index c34dbca..8dd5162 100644 --- a/debugging_demo/Makefile +++ b/debugging_demo/Makefile @@ -8,7 +8,9 @@ CFLAGS += -fno-builtin # EFI requires -fshort-wchar CFLAGS += -fshort-wchar CFLAGS += -fno-common -CFLAGS += -fno-strict-aliasing -g +CFLAGS += -fno-strict-aliasing +# Enable debug info generation at compile time +CFLAGS += -g # EFI uses Microsoft ABI so no red zone is defined CFLAGS += -mno-red-zone @@ -17,10 +19,10 @@ CFLAGS += -fpie #CFLAGS += -fno-pie -no-pie -static # the UEFI PE executables must be relocatable -CFLAGS += -fPIC +CFLAGS += -fpic CFLAGS += -ffunction-sections CFLAGS += -fdata-sections -CFLAGS += -flto +# CFLAGS += -flto !!Do not use it. All is written to special ELF sections # function calls must include the number of arguments passed to the functions CFLAGS += -maccumulate-outgoing-args @@ -64,16 +66,15 @@ SECTIONS=.text .sdata .data .dynamic .dynsym .rel .rela .reloc all: clean MemtestEfi.efi move run -MemtestEfi.efi: OUTPUT/MemtestEfi.so +MemtestEfi.efi: MemtestEfi.so objcopy $(foreach sec,$(SECTIONS), -j $(sec)) --target=pei-x86-64 --subsystem=10 $< $@ -OUTPUT/$(MAIN_FILE).so: $(OBJS) - ld -shared -Bsymbolic -Telf_x86_64_efi.lds -o $@ $^ +$(MAIN_FILE).so: $(OBJS) + ld -shared -Bsymbolic -fuse-linker-plugin -Telf_x86_64_efi.lds -o $@ $^ #rm $^ $(MAIN_FILE).o: $(MAIN_FILE).c $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -include memtest86+/efi/Include/Efi_Defs.h \ -I . \ -I"memtest86+" \ -I"memtest86+/efi/Include" @@ -134,7 +135,7 @@ BasePrintLib.o: PrintLib.o PrintLibInternal.o rm $^ %.o: memtest86+/efi/Include/src/UefiDevicePathLib/%.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ + $(CC) $(CFLAGS) $(PREPROCESSOR) -flto $(M) -c -o $@ $< \ -I"memtest86+/efi/Include" UefiDevicePathLib2.o: $(UefiDevicePathLib_OBJS) @@ -156,15 +157,14 @@ BaseLib.o: $(BaseLib_OBJS) -I"memtest86+/efi/Include" clean: - rm -f OUTPUT/* rm -f memtest86+/*.o rm -f *.o - rm -f MemtestEfi.obj + rm -f MemtestEfi.o rm -f MemtestEfi.map rm -f MemtestEfi.dll rm -f MemtestEfi.efi rm -f MemtestEfi.txt - rm -f Efi_Defs.obj + rm -f Efi_Defs.o move: diff --git a/debugging_demo/MemtestEfi.efi b/debugging_demo/MemtestEfi.efi deleted file mode 100755 index 6f7aff2..0000000 Binary files a/debugging_demo/MemtestEfi.efi and /dev/null differ diff --git a/debugging_demo/MemtestEfi.o b/debugging_demo/MemtestEfi.o deleted file mode 100644 index 9a794a4..0000000 Binary files a/debugging_demo/MemtestEfi.o and /dev/null differ diff --git a/debugging_demo/OUTPUT/MemtestEfi.so b/debugging_demo/OUTPUT/MemtestEfi.so deleted file mode 100755 index ff4f488..0000000 Binary files a/debugging_demo/OUTPUT/MemtestEfi.so and /dev/null differ diff --git a/debugging_demo/UefiBootServicesTableLib.o b/debugging_demo/UefiBootServicesTableLib.o deleted file mode 100644 index 59a364b..0000000 Binary files a/debugging_demo/UefiBootServicesTableLib.o and /dev/null differ diff --git a/debugging_demo/UefiDebugLibStdErr.o b/debugging_demo/UefiDebugLibStdErr.o deleted file mode 100644 index 703d044..0000000 Binary files a/debugging_demo/UefiDebugLibStdErr.o and /dev/null differ diff --git a/debugging_demo/UefiDevicePathLib2.o b/debugging_demo/UefiDevicePathLib2.o deleted file mode 100644 index ad7a25c..0000000 Binary files a/debugging_demo/UefiDevicePathLib2.o and /dev/null differ diff --git a/debugging_demo/UefiLib2.o b/debugging_demo/UefiLib2.o deleted file mode 100644 index eaaf603..0000000 Binary files a/debugging_demo/UefiLib2.o and /dev/null differ diff --git a/debugging_demo/UefiMemoryAllocationLib.o b/debugging_demo/UefiMemoryAllocationLib.o deleted file mode 100644 index 4e4bccc..0000000 Binary files a/debugging_demo/UefiMemoryAllocationLib.o and /dev/null differ diff --git a/debugging_demo/UefiRuntimeServicesTableLib.o b/debugging_demo/UefiRuntimeServicesTableLib.o deleted file mode 100644 index 18da417..0000000 Binary files a/debugging_demo/UefiRuntimeServicesTableLib.o and /dev/null differ diff --git a/efi_memtest/Makefile_orig b/efi_memtest/Makefile_orig deleted file mode 100644 index 57f4f7c..0000000 --- a/efi_memtest/Makefile_orig +++ /dev/null @@ -1,214 +0,0 @@ -MAIN_FILE = MemtestEfi - -CC = gcc - -# Warnings -CFLAGS = -Werror -Wall -Wno-array-bounds -Wno-address -CFLAGS += -fno-builtin -# EFI requires -fshort-wchar -CFLAGS += -fshort-wchar -CFLAGS += -fno-common -CFLAGS += -fno-strict-aliasing -g -# EFI uses Microsoft ABI so no red zone is defined -CFLAGS += -mno-red-zone - -# use %rip-relative addressing wherever possible?? Or not? -CFLAGS += -fpie -#CFLAGS += -fno-pie -no-pie -static - -CFLAGS += -fPIC -CFLAGS += -ffunction-sections -CFLAGS += -fdata-sections -CFLAGS += -flto -CFLAGS += -maccumulate-outgoing-args -CFLAGS += -fno-asynchronous-unwind-tables -CFLAGS += -nostdlib -CFLAGS += -mcmodel=small -CFLAGS += -fno-stack-protector - -M64=-m64 - -M32=-m32 - -M=$(M64) - -PREPROCESSOR=-DUEFI -DUSING_LTO -Os \ - -D DISABLE_NEW_DEPRECATED_INTERFACES "-DEFIAPI=__attribute__((ms_abi))" - -OBJS=Efi_Defs.obj config.o controller.o cpuid.o display.o dmi.o error.o init.o \ - lib.o logger.o main.o memory_tables.o memsize.o page_allocator.o patn.o pci.o reloc.o \ - screen_buffer.o random.o smp.o spd.o test.o vmem.o \ - BaseLib.o BaseMemoryLib.o BasePrintLib.o \ - UefiDebugLibStdErr.o UefiDevicePathLib2.o UefiLib2.o ApplicationEntryPoint.o \ - BaseDebugPrintErrorLevelLib.o UefiMemoryAllocationLib.o BasePcdLibNull.o \ - UefiRuntimeServicesTableLib.o UefiBootServicesTableLib.o MemtestEfi.obj - - -BaseMemoryLib_OBJS=CompareMemWrapper.o CopyMem.o CopyMemWrapper.o IsZeroBufferWrapper.o \ - MemLibGeneric.o MemLibGuid.o ScanMem16Wrapper.o ScanMem32Wrapper.o ScanMem64Wrapper.o \ - ScanMem8Wrapper.o SetMem.o SetMem16Wrapper.o SetMem32Wrapper.o SetMem64Wrapper.o \ - SetMemWrapper.o ZeroMemWrapper.o - -UefiDevicePathLib_OBJS=DevicePathFromText.o DevicePathToText.o DevicePathUtilities.o \ - DevicePathUtilitiesDxeSmm.o DevicePathUtilitiesStandaloneMm.o UefiDevicePathLib.o \ - UefiDevicePathLibOptionalDevicePathProtocol.o - -BaseLib_OBJS=ARShiftU64.o BitField.o CheckSum.o CpuDeadLoop.o Cpu.o DivU64x64Remainder.o \ - DivU64x32Remainder.o DivU64x32.o DivS64x64Remainder.o FilePaths.o GetPowerOfTwo64.o \ - GetPowerOfTwo32.o HighBitSet64.o HighBitSet32.o LongJump.o LRotU64.o LowBitSet64.o \ - LowBitSet32.o LRotU32.o LShiftU64.o Math64.o ModU64x32.o MultU64x64.o MultU64x32.o MultS64x64.o \ - RRotU32.o RRotU64.o RShiftU64.o SafeString.o String.o SetJump.o SwapBytes64.o SwapBytes32.o \ - SwapBytes16.o SwitchStack.o Unaligned.o - - - -LIBRARIES=OUTPUT/MemtestEfi.lib - -all: clean MemtestEfi.efi move run - - -$(MAIN_FILE).efi: $(MAIN_FILE).dll - ./memtest86+/efi/Include/GenFw -e UEFI_APPLICATION -o $(MAIN_FILE).efi $(MAIN_FILE).dll - - -$(MAIN_FILE).dll: $(MAIN_FILE).lib - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) $(LIBRARIES) -o $(MAIN_FILE).dll \ - -nostdlib \ - -Wl,-n,-q,--gc-sections \ - -Wl,--entry,_ModuleEntryPoint \ - -Wl,-Map,$(MAIN_FILE).map,--whole-archive \ - -Wl,-melf_x86_64,--oformat=elf64-x86-64,-pie \ - -Wl,--defsym=PECOFF_HEADER_SIZE=0x228 \ - -Wl,--script=memtest86+/efi/Include/GccBase.lds \ - -z common-page-size=0x40 \ - -u _ModuleEntryPoint \ - -DSTRING_ARRAY_NAME=${MAIN_FILE}Strings - objcopy --strip-unneeded -R .eh_frame -v $(MAIN_FILE).dll $(MAIN_FILE).dll - strip -R .strtab MemtestEfi.dll - -$(MAIN_FILE).lib: $(OBJS) - gcc-ar crv OUTPUT/$(MAIN_FILE).lib $^ - #rm $^ - -$(MAIN_FILE).obj: $(MAIN_FILE).c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -o $(MAIN_FILE).obj \ - -MMD -MF OUTPUT/$(MAIN_FILE).obj.deps \ - -c \ - -include memtest86+/efi/Include/Efi_Defs.h \ - -DSTRING_ARRAY_NAME=${MAIN_FILE}Strings \ - -I . \ - -I"memtest86+" \ - -I"memtest86+/efi/Include" \ - $(MAIN_FILE).c - -Efi_Defs.obj: memtest86+/efi/Include/Efi_Defs.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -o $@ $< \ - -c \ - -I"memtest86+/efi/Include" - -%.o: memtest86+/%.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+/efi" - -%.o: memtest86+/efi/Include/src/%.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+/efi/Include" \ - -I"memtest86+/efi/Include/Library" - -%.o: memtest86+/efi/Include/src/UefiLib/%.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+/efi/Include" \ - -I"memtest86+/efi/Include/Protocol" \ - -I"memtest86+/efi/Include/Guid" - -BasePcdLibNull.o: memtest86+/efi/Include/src/PcdLib.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+/efi/Include" - -UefiMemoryAllocationLib.o: memtest86+/efi/Include/src/MemoryAllocationLib.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+/efi/Include" - -UefiLib2.o: Acpi.o Console.o UefiDriverModel.o UefiLib.o UefiLibPrint.o UefiNotTiano.o - ld -r -o $@ $^ - rm $^ - -%.o: memtest86+/efi/Include/src/UefiDebugLibStdErr/%.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+/efi/Include" - -UefiDebugLibStdErr.o: DebugLib.o DebugLibConstructor.o - ld -r -o $@ $^ - rm $^ - -%.o: memtest86+/efi/Include/src/BaseMemoryLib/%.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+/efi/Include" - -BaseMemoryLib.o: $(BaseMemoryLib_OBJS) - ld -r -o $@ $^ - rm $^ - -%.o: memtest86+/efi/Include/src/BasePrintLib/%.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+/efi/Include" - -BasePrintLib.o: PrintLib.o PrintLibInternal.o - ld -r -o $@ $^ - rm $^ - -%.o: memtest86+/efi/Include/src/UefiDevicePathLib/%.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+/efi/Include" - -UefiDevicePathLib2.o: $(UefiDevicePathLib_OBJS) - ld -r -o $@ $^ - rm $^ - -%.o: memtest86+/efi/Include/src/BaseLib/%.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+/efi/Include" - -BaseLib.o: $(BaseLib_OBJS) - ld -r -o $@ $^ - rm $^ - -%.o: memtest86+/efi/%.c - $(CC) $(CFLAGS) $(PREPROCESSOR) $(M) -c -o $@ $< \ - -I"memtest86+" \ - -I"memtest86+/efi" \ - -I"memtest86+/efi/Include" - -clean: - rm -f OUTPUT/* - rm -f memtest86+/*.o - rm -f *.o - rm -f MemtestEfi.obj - rm -f MemtestEfi.map - rm -f MemtestEfi.dll - rm -f MemtestEfi.efi - rm -f MemtestEfi.txt - rm -f Efi_Defs.obj - - -move: - cp MemtestEfi.efi ../test_code/hda-contents - -run: - sudo ./run.sh - - - - - - - - - - - - - - - - diff --git a/efi_memtest/OUTPUT/MemtestEfi.lib b/efi_memtest/OUTPUT/MemtestEfi.lib index 1b115fe..b5d6f1f 100644 Binary files a/efi_memtest/OUTPUT/MemtestEfi.lib and b/efi_memtest/OUTPUT/MemtestEfi.lib differ diff --git a/test_code/run.sh b/test_code/run.sh index b850537..bcbe3cd 100755 --- a/test_code/run.sh +++ b/test_code/run.sh @@ -2,13 +2,15 @@ #(cd hda-contents; rm memtest_log; echo -n -e '\x00' >> memtest_log) +sudo kvm -bios OVMF.fd \ + --drive file=fat:rw:hda-contents,index=0,media=disk,format=raw -net none -cpu host # sudo kvm -bios OVMF.fd -serial tcp::666,server -s \ # --drive file=fat:rw:hda-contents,index=0,media=disk,format=raw \ # --drive file=fat:rw:hdb-contents,index=1,media=disk,format=raw -net none -cpu host -sudo kvm -bios OVMF.fd -s -S \ - --drive file=fat:rw:hda-contents,index=0,media=disk,format=raw -net none -cpu host +#sudo kvm -bios OVMF.fd -s -S \ +# --drive file=fat:rw:hda-contents,index=0,media=disk,format=raw -net none -cpu host #-drive file=vm-disk-2G,format=raw,index=3,media=disk #-nographic -- cgit v1.2.3-55-g7522