mirror of
				https://gitlab.com/qemu-project/qboot.git
				synced 2024-02-13 08:33:40 +08:00 
			
		
		
		
	 a5300c4949
			
		
	
	a5300c4949
	
	
	
		
			
			The switch to meson in commit fd2aada36b ("Add meson build") had two
major behavior changes for the ELF binary build step:
* ELF binary is no longer build as x86_64 on x86_64
* ELF binary is build as position independent executable on systems with a
  "--enable-default-pie" gcc
The latter will create a slightly larger than 64KB bios.bin which causes an
error when Qemu tries to load it:
  qemu: could not load PC BIOS 'qboot/build/bios.bin'
This behavior change was introduced because the elf linker step was changed
from using ld directly to using cc. Basically something like following
Makefile change:
   bios.bin.elf: $(obj-y) flat.lds
  -        $(LD) -T flat.lds -o bios.bin.elf $(obj-y)
  +        $(CC) -o bios.bin.elf $(obj-y) -Wl,--no-undefined -Wl,--as-needed -nostdlib -m32 -Wl,--build-id=none -Wl,-Tflat.lds
GCC will then take care of calling ld with the appropriate arguments. And
one of these arguments for the "--enable-default-pie" gcc is "-pie":
  $(LD) --build-id --eh-frame-hdr -m elf_i386 --hash-style=gnu -dynamic-linker /lib/ld-linux.so.2 -pie -o bios.bin.elf $(obj-y) --no-undefined --as-needed --build-id=none -Tflat.lds
This default behavior of gcc must be suppressed by adding -no-pie to the
arguments when linking the object files.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
		
	
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Meson
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Meson
		
	
	
	
	
	
| project('qboot', 'c', meson_version: '>=0.49.0')
 | |
| 
 | |
| cc = meson.get_compiler('c')
 | |
| objcopy = find_program('objcopy')
 | |
| 
 | |
| c_args = [
 | |
|   '-m32',
 | |
|   '-march=i386',
 | |
|   '-mregparm=3',
 | |
|   '-fno-stack-protector',
 | |
|   '-fno-delete-null-pointer-checks',
 | |
|   '-ffreestanding',
 | |
|   '-mstringop-strategy=rep_byte',
 | |
|   '-minline-all-stringops',
 | |
|   '-fno-pic',
 | |
| ]
 | |
| 
 | |
| link_args = ['-nostdlib', '-m32']
 | |
| link_args += cc.get_supported_link_arguments('-Wl,--build-id=none')
 | |
| link_args += '-Wl,-T' + meson.current_source_dir() / 'flat.lds'
 | |
| link_args += cc.get_supported_link_arguments(['-no-pie'])
 | |
| 
 | |
| elf = executable(
 | |
|   'bios.bin.elf',
 | |
|   files(
 | |
|     'code16.c',
 | |
|     'code32seg.c',
 | |
|     'cstart.S',
 | |
|     'entry.S',
 | |
|     'fw_cfg.c',
 | |
|     'hwsetup.c',
 | |
|     'linuxboot.c',
 | |
|     'main.c',
 | |
|     'malloc.c',
 | |
|     'mptable.c',
 | |
|     'pci.c',
 | |
|     'printf.c',
 | |
|     'string.c',
 | |
|     'smbios.c',
 | |
|     'tables.c',
 | |
|   ),
 | |
|   c_args: c_args,
 | |
|   include_directories: include_directories('include'),
 | |
|   link_args: link_args,
 | |
| )
 | |
| 
 | |
| bin = custom_target(
 | |
|   'bios.bin',
 | |
|   output: 'bios.bin',
 | |
|   input: elf,
 | |
|   command: [objcopy, '-O', 'binary', '@INPUT@', '@OUTPUT@'],
 | |
|   build_by_default: true,
 | |
| )
 |