{simple,shoddy,smart} minsize-oriented linker
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.5 KiB

  1. import os.path
  2. import subprocess
  3. import sys
  4. from .parse import *
  5. from .shared import eprintf
  6. def cc_relink_objs(verbose, cc_bin, arch, inputs, output, cflags):
  7. archflag = '-m64' if arch == "x86_64" else '-m32'
  8. cctyp, ccver = get_cc_version(cc_bin)
  9. assert cctyp == "gcc", "A GCC compiler is needed for relinking objects!"
  10. relink_arg = "-flinker-output=rel" if ccver < (9,0) else "-flinker-output=nolto-rel"
  11. args = [cc_bin, archflag, '-nostartfiles', '-nostdlib', \
  12. '-r', relink_arg, '-o', output] + cflags + inputs
  13. if verbose: eprintf("cc: %s" % repr(args))
  14. subprocess.check_call(args, stdout=subprocess.DEVNULL)
  15. def nasm_assemble_elfhdr(verbose, nasm_bin, arch, rtdir, intbl, output, asflags):
  16. if rtdir[-1] != '/': rtdir = rtdir + '/'
  17. archflag = 'elf64' if arch == "x86_64" else 'elf32'
  18. args = [nasm_bin, '-I', rtdir, '-f', archflag] + asflags + [intbl, '-o', output]
  19. if verbose: eprintf("nasm: %s" % repr(args))
  20. subprocess.check_call(args, stdout=subprocess.DEVNULL)
  21. def ld_link_final(verbose, cc_bin, arch, lddir, inobjs, output, ldflags, debug):
  22. archflag = '-m64' if arch == "x86_64" else '-m32'
  23. args = [cc_bin, archflag, '-T', lddir+'/link.ld', '-no-pie']
  24. if not debug:
  25. args.append('-Wl,--oformat=binary')
  26. #args = [*args, '-T', lddir+'/link.ld', '-Wl,--oformat=binary']
  27. args += ['-nostartfiles', '-nostdlib', '-o', output, *inobjs, *ldflags]
  28. if verbose: eprintf("ld: %s" % repr(args))
  29. subprocess.check_call(args, stdout=subprocess.DEVNULL)