From 4fc1f5444a74a88af299b1993e0a7fe89d98c01a Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 10 Feb 2019 19:25:22 +0100 Subject: [PATCH] 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. --- module/mescc.scm | 14 ++++++++++++-- module/mescc/mescc.scm | 11 ++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/module/mescc.scm b/module/mescc.scm index 873e553d..749be811 100644 --- a/module/mescc.scm +++ b/module/mescc.scm @@ -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: 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)) diff --git a/module/mescc/mescc.scm b/module/mescc/mescc.scm index 875530d4..5ac29078 100644 --- a/module/mescc/mescc.scm +++ b/module/mescc/mescc.scm @@ -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"