As per suggestion we should use g0 for turning off debug information in the
compiled go file.
I did some preparatory work in case we will add more levels in the future
as well.
See diff attached.
>>>>>>>>>>>>>>>>>>>>< stis@lapwine:~/guile-work$ guile/meta/guild compile
--help
Usage: compile [OPTION] FILE...
Compile each Guile source file FILE into a Guile object.
-h, --help print this help message
-L, --load-path=DIR add DIR to the front of the module load path
-o, --output=OFILE write output to OFILE
-W, --warn=WARNING emit warnings of type WARNING; use `--warn=help'
for a list of available warnings
-O, --optimize=OPT specify optimization passes to run; use `-Ohelp'
for a list of available optimizations
-g, --debug=OPT specify debug information availability; use `-ghelp
'
for a list of available debug options
-f, --from=LANG specify a source language other than `scheme'
-t, --to=LANG specify a target language other than `bytecode'
-T, --target=TRIPLET produce bytecode for host TRIPLET
Note that auto-compilation will be turned off.
Report bugs to <[email protected]>.
>>>>>>>>>>>>>>>>>> stis@lapwine:~/guile-work$ guile/meta/guild compile -g0
test.scm
wrote `/home/stis/guile-work/guile/cache/guile/ccache/2.2-LE-8-3.A/home/st
is/guile-work/test.scm.go'
stis@lapwine:~/guile-work$ objdump -h ~/guile-work/guile/cache/guile/ccach
e/2.2-LE-8-3.A/home/stis/guile-work/test.scm.go
/home/stis/guile-work/guile/cache/guile/ccache/2.2-LE-8-3.A/home/stis/guil
e-work/test.scm.go: file format elf64-little
Sections:
Idx Name Size VMA LMA File off
Algn
0 .guile.procprops 00000000 0000000000000000 0000000000000000 0001041
8 2**3
CONTENTS, READONLY
1 .rodata 00000013 0000000000000138 0000000000000138 00000138
2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .data 00000028 0000000000010000 0000000000010000 00010000
2**3
CONTENTS, ALLOC, LOAD, DATA
3 .rtl-text 00000050 00000000000000e8 00000000000000e8 000000e8
2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .dynamic 00000060 0000000000000150 0000000000000150 00000150
2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .guile.arities 0000002f 0000000000000000 0000000000000000 000103e8
2**3
CONTENTS, READONLY
6 .guile.arities.strtab 00000016 0000000000000000 0000000000000000 00
010450 2**3
CONTENTS, READONLY
7 .guile.docstrs 00000000 0000000000000000 0000000000000000 00010418
2**3
CONTENTS, READONLY
8 .guile.docstrs.strtab 00000001 0000000000000000 0000000000000000 00
010468 2**3
CONTENTS, READONLY
9 000000e8 0000000000000000 0000000000000000 00000000
2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
10 000003c0 0000000000000000 0000000000000000 00010028
2**3
CONTENTS, READONLY
>>>>>>>>>>>>>>>>>>>>>>>>> stis@lapwine:~/guile-work$ guile/meta/guild
compile -g1 test.scm
wrote `/home/stis/guile-work/guile/cache/guile/ccache/2.2-LE-8-3.A/home/st
is/guile-work/test.scm.go'
stis@lapwine:~/guile-work$ objdump -h ~/guile-work/guile/cache/guile/ccach
e/2.2-LE-8-3.A/home/stis/guile-work/test.scm.go
/home/stis/guile-work/guile/cache/guile/ccache/2.2-LE-8-3.A/home/stis/guil
e-work/test.scm.go: file format elf64-little
Sections:
Idx Name Size VMA LMA File off
Algn
0 .guile.procprops 00000000 0000000000000000 0000000000000000 0001055
8 2**3
CONTENTS, READONLY
1 .rodata 00000013 0000000000000138 0000000000000138 00000138
2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .data 00000028 0000000000010000 0000000000010000 00010000
2**3
CONTENTS, ALLOC, LOAD, DATA
3 .rtl-text 00000050 00000000000000e8 00000000000000e8 000000e8
2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .dynamic 00000060 0000000000000150 0000000000000150 00000150
2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .guile.arities 0000002f 0000000000000000 0000000000000000 00010528
2**3
CONTENTS, READONLY
6 .guile.arities.strtab 00000016 0000000000000000 0000000000000000 00
010640 2**3
CONTENTS, READONLY
7 .guile.docstrs 00000000 0000000000000000 0000000000000000 00010558
2**3
CONTENTS, READONLY
8 .guile.docstrs.strtab 00000001 0000000000000000 0000000000000000 00
010658 2**3
CONTENTS, READONLY
9 .debug_info 00000034 0000000000000000 0000000000000000 00010558
2**3
CONTENTS, READONLY, DEBUGGING
10 .debug_abbrev 00000019 0000000000000000 0000000000000000 00010590
2**3
CONTENTS, READONLY, DEBUGGING
11 .debug_str 00000014 0000000000000000 0000000000000000 000105b0
2**3
CONTENTS, READONLY, DEBUGGING
12 .debug_loc 00000000 0000000000000000 0000000000000000 000105c8
2**3
CONTENTS, READONLY, DEBUGGING
13 .debug_line 00000039 0000000000000000 0000000000000000 000105c8
2**3
CONTENTS, READONLY, DEBUGGING
14 000000e8 0000000000000000 0000000000000000 00000000
2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
15 00000500 0000000000000000 0000000000000000 00010028
2**3
CONTENTS, READONLY
>>>>>>>>>>>>>>>>>>> stis@lapwine:~/guile-work$ guile/meta/guild compile
-ghelp
The available debug options are:
-gdebug-info
To disable an optimization, prepend it with `no-', for example
`-gno-debug-info'
You may also specify optimization levels as `-g0', `-g1'.
Currently `-g0' removes debug info from the compiled file
and remove all debug information,
`-g1' have all debug info inserted in the compiled file.
The default is equivalent to `-g1'.
On Fri, May 19, 2017 at 11:52 PM, Stefan Israelsson Tampe <
[email protected]> wrote:
> Hi,
>
> I have now tested to compile a scm file with -O0, checked with objdump
> that the dwarf information is gone and than load it and all seams fine.
>
> diff is attached to this email
>
> On Fri, May 19, 2017 at 9:10 PM, Stefan Israelsson Tampe <
> [email protected]> wrote:
>
>> I found a bug in the call-with-values part of the diff. That is fixed now
>>
>> On Fri, May 19, 2017 at 8:48 PM, Stefan Israelsson Tampe <
>> [email protected]> wrote:
>>
>>> I manage to send the mail to fast. Here is the diff
>>>
>>> On Fri, May 19, 2017 at 8:46 PM, Stefan Israelsson Tampe <
>>> [email protected]> wrote:
>>>
>>>> Hi,
>>>>
>>>> I've decided to start help developing guile. wingo has a list at
>>>>
>>>> https://wingolog.org/archives/2016/02/04/guile-compiler-tasks
>>>>
>>>> I took, as a start, the first item: stripping binaries.
>>>>
>>>> one can remove debug information through
>>>> guild compile -O0
>>>>
>>>> After some thought I think that the diff following this email adresses
>>>> this, any comments are
>>>> helpful else I will compile and start testing this option
>>>>
>>>
>>>
>>
>
diff --git a/module/language/cps/compile-bytecode.scm
b/module/language/cps/compile-bytecode.scm
index c283eb6..b6d4bf7 100644
--- a/module/language/cps/compile-bytecode.scm
+++ b/module/language/cps/compile-bytecode.scm
@@ -587,7 +587,9 @@
(intmap-for-each (lambda (kfun body)
(compile-function (intmap-select exp body) asm))
(compute-reachable-functions exp 0))
- (values (link-assembly asm #:page-aligned? (kw-arg-ref opts #:to-file? #f))
+ (values (link-assembly asm
+ #:page-aligned? (kw-arg-ref opts #:to-file? #f)
+ #:debug? (kw-arg-ref opts #:debug-info? #t))
env
env)))
diff --git a/module/scripts/compile.scm b/module/scripts/compile.scm
index 939fb25..ff20bca 100644
--- a/module/scripts/compile.scm
+++ b/module/scripts/compile.scm
@@ -42,6 +42,7 @@
#:export (compile))
(define %summary "Compile a file.")
+(define debug-options '(#:debug-info? #t))
(define (fail . messages)
@@ -116,6 +117,28 @@
(return-option (substring arg 3) #f))
(else
(return-option arg #t)))))
+
+ (option '(#\g "debug") #t #f
+ (lambda (opt name arg result)
+ (define (return val)
+ (alist-cons 'debug val result))
+ (define (return-option name val)
+ (let ((kw (symbol->keyword
+ (string->symbol (string-append name "?")))))
+ (unless (memq kw debug-options)
+ (fail "Unknown debug option `~a'" name))
+ (return (list kw val))))
+ (cond
+ ((string=? arg "help")
+ (show-debug-help)
+ (exit 0))
+ ((equal? arg "0") (return '(#:debug-info? #f)))
+ ((equal? arg "1") (return '(#:debug-info? #t)))
+ ((string-prefix? "no-" arg)
+ (return-option (substring arg 3) #f))
+ (else
+ (return-option arg #t)))))
+
(option '(#\f "from") #t #f
(lambda (opt name arg result)
(if (assoc-ref result 'from)
@@ -185,6 +208,27 @@ There is NO WARRANTY, to the extent permitted by law.~%"))
(format #t "everything. The default is equivalent to `-O2'.")
(format #t "~%"))
+(define (show-debug-help)
+ (format #t "The available debug options are:~%~%")
+ (let lp ((options debug-options))
+ (match options
+ (() #t)
+ ((kw val . options)
+ (let ((name (string-trim-right (symbol->string (keyword->symbol kw))
+ #\?)))
+ (format #t " -g~a~%"
+ (if val name (string-append "no-" name)))
+ (lp options)))))
+ (format #t "~%")
+ (format #t "To disable an debug info level, prepend it with `no-', for
example~%")
+ (format #t "`-gno-debug-info'~%~%")
+ (format #t "You may also specify debug levels as `-g0', `-g1'.~%")
+ (format #t "Currently `-g0' removes debug info from the compiled file~%")
+ (format #t "and remove all debug information,~%")
+ (format #t "`-g1' have all debug info inserted in the compiled file.~%")
+ (format #t "The default is equivalent to `-g1'.")
+ (format #t "~%"))
+
(define (compile . args)
(let* ((options (parse-args args))
@@ -195,6 +239,7 @@ There is NO WARRANTY, to the extent permitted by law.~%"))
(lambda (opt)
(match opt
(('optimizations . opts) opts)
+ (('debug . opts) opts)
(_ '())))
options)))
(from (or (assoc-ref options 'from) 'scheme))
@@ -217,7 +262,8 @@ Compile each Guile source file FILE into a Guile object.
for a list of available warnings
-O, --optimize=OPT specify optimization passes to run; use `-Ohelp'
for a list of available optimizations
-
+ -g, --debug=OPT specify debug information availability; use `-ghelp'
+ for a list of available debug options
-f, --from=LANG specify a source language other than `scheme'
-t, --to=LANG specify a target language other than `bytecode'
-T, --target=TRIPLET produce bytecode for host TRIPLET
diff --git a/module/system/vm/assembler.scm b/module/system/vm/assembler.scm
index 8d71dc5..bf96d3b 100644
--- a/module/system/vm/assembler.scm
+++ b/module/system/vm/assembler.scm
@@ -2194,7 +2194,7 @@ procedure with label @var{rw-init}. @var{rw-init} may be
false. If
;; The size of a procprops entry, in bytes.
(define procprops-size 8)
-
+
(define (link-procprops asm)
(define (assoc-remove-one alist key value-pred)
(match alist
@@ -2575,7 +2575,7 @@ procedure with label @var{rw-init}. @var{rw-init} may be
false. If
(make-object asm '.debug_line bv line-relocs '()
#:type SHT_PROGBITS #:flags 0)))))
-(define (link-objects asm)
+(define* (link-objects asm debug?)
(let*-values (;; Link procprops before constants, because it probably
;; interns more constants.
((procprops) (link-procprops asm))
@@ -2588,16 +2588,21 @@ procedure with label @var{rw-init}. @var{rw-init} may
be false. If
((symtab strtab) (link-symtab (linker-object-section text)
asm))
((arities arities-strtab) (link-arities asm))
((docstrs docstrs-strtab) (link-docstrs asm))
- ((dinfo dabbrev dstrtab dloc dline) (link-debug asm))
+ ((debug-tables)
+ (values
+ (if debug?
+ (call-with-values (lambda () (link-debug asm)) list)
+ '())))
;; This needs to be linked last, because linking other
;; sections adds entries to the string table.
((shstrtab) (link-shstrtab asm)))
(filter identity
- (list text ro frame-maps rw dt symtab strtab
- arities arities-strtab
- docstrs docstrs-strtab procprops
- dinfo dabbrev dstrtab dloc dline
- shstrtab))))
+ (append
+ (list text ro frame-maps rw dt symtab strtab
+ arities arities-strtab
+ docstrs docstrs-strtab procprops)
+ debug-tables
+ (list shstrtab)))))
@@ -2606,9 +2611,10 @@ procedure with label @var{rw-init}. @var{rw-init} may
be false. If
;;; High-level public interfaces.
;;;
-(define* (link-assembly asm #:key (page-aligned? #t))
+(define* (link-assembly asm #:key (page-aligned? #t) (debug? #t))
"Produce an ELF image from the code and data emitted into @var{asm}.
The result is a bytevector, by default linked so that read-only and
writable data are on separate pages. Pass @code{#:page-aligned? #f} to
-disable this behavior."
- (link-elf (link-objects asm) #:page-aligned? page-aligned?))
+disable this behavior. Pass @code{debug? #f} to remove debug info from
+the elf image"
+ (link-elf (link-objects asm debug?) #:page-aligned? page-aligned?))