mescc: Support -nodefaultlibs, -nostartfiles, -nostdlib.

* module/mescc.scm (parse-opts): Parse -nodefaultlibs, -nostartfiles, -nostdlib.
* module/mescc/mescc.scm (mescc:link): Handle -nodefaultlibs, -nostdlib.
(hex2->elf): Handle -nostartfiles, -nostdlib.
This commit is contained in:
Jan Nieuwenhuizen 2019-02-10 19:25:22 +01:00
parent d0e6228fa1
commit 4fc1f5444a
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
2 changed files with 20 additions and 5 deletions

View File

@ -58,12 +58,15 @@
(compile (single-char #\S))
(define (single-char #\D) (value #t))
(debug-info (single-char #\g))
(dumpmachine (single-char #\d))
(dumpmachine)
(help (single-char #\h))
(include (single-char #\I) (value #t))
(library-dir (single-char #\L) (value #t))
(library (single-char #\l) (value #t))
(machine (single-char #\m) (value #t))
(nodefaultlibs)
(nostartfiles)
(nostdlib)
(preprocess (single-char #\E))
(std (value #t))
(output (single-char #\o) (value #t))
@ -97,6 +100,9 @@ Usage: mescc [OPTION]... FILE...
-L DIR append DIR to library path
-l LIBNAME link with LIBNAME
-m BITS compile for BITS bits [32]
-nodefaultlibs do not use libc.o when linking
-nostartfiles do not use crt1.o when linking
-nostdlib do not use crt1.o or libc.o when linking
-o FILE write output to FILE
-O LEVEL use optimizing LEVEL
-S preprocess and compile only; do not assemble or link
@ -119,7 +125,11 @@ General help using GNU software: <http://gnu.org/gethelp/>
options))))
(define (mescc:main args)
(let* ((single-dash-options '("-dumpmachine" "-std"))
(let* ((single-dash-options '("-dumpmachine"
"-nodefaultlibs"
"-nostartfiles"
"-nostdlib"
"-std"))
(args (map (lambda (o)
(if (member o single-dash-options) (string-append "-" o)
o))

View File

@ -135,9 +135,11 @@
(hex2-files (if (null? infos) hex2-files
(append hex2-files
(list (infos->hex2 options hex2-file-name infos)))))
(default-libraries (if (or (option-ref options 'nodefaultlibs #f)
(option-ref options 'nostdlib #f)) '()
'("c")))
(libraries (filter-map (multi-opt 'library) options))
(libraries (if (pair? libraries) libraries '("c")))
(libraries (if (equal? libraries '("none")) '() libraries))
(libraries (delete-duplicates (append libraries default-libraries)))
(hex2-libraries (map (cut find-library options ".o" <>) libraries))
(hex2-files (append hex2-files hex2-libraries))
(S-files (append S-files (map (cut find-library options ".S" <>) libraries)))
@ -208,12 +210,15 @@
(elf-footer (or elf-footer
(arch-find options (string-append
"elf" machine "-footer-single-main.hex2"))))
(start-files (if (or (option-ref options 'nostartfiles #f)
(option-ref options 'nostdlib #f)) '()
`("-f" ,(arch-find options "crt1.o"))))
(command `(,hex2
"--LittleEndian"
"--Architecture" ,architecture
"--BaseAddress" ,base-address
"-f" ,(arch-find options (string-append "elf" machine "-header.hex2"))
"-f" ,(arch-find options "crt1.o")
,@start-files
,@(append-map (cut list "-f" <>) hex2-files)
"-f" ,elf-footer
"--exec_enable"