From 5beb09ef8e08ea711152a43f90a5620c5f8b8c3c Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Thu, 3 Mar 2016 19:36:57 +0100 Subject: [PATCH 1/8] added linker-scripts for gcc --- doc/src/reference.xml | 7 +++++++ src/tools/gcc.jam | 14 ++++++++++++++ test/gcc_runtime.py | 5 ++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/src/reference.xml b/doc/src/reference.xml index a66eb75a6d..609a3272f2 100644 --- a/doc/src/reference.xml +++ b/doc/src/reference.xml @@ -975,6 +975,13 @@ using gcc : &toolset_ops; ; or rc for borland's resource compiler. + + linker-script + + + Specifies a linker script to be used for linking. Several are allowed and each file must have the extension .ld + + diff --git a/src/tools/gcc.jam b/src/tools/gcc.jam index 0f346a5015..67bd135054 100644 --- a/src/tools/gcc.jam +++ b/src/tools/gcc.jam @@ -49,6 +49,9 @@ type.set-generated-target-suffix OBJ : gcc : o ; type.set-generated-target-suffix OBJ : gcc windows : o ; type.set-generated-target-suffix OBJ : gcc cygwin : o ; +# Add Gnu linker scripts +feature.feature linker-script : : free dependency ; +type.register LINKERSCRIPT : ld : gcc ; # Initializes the gcc toolset for the given version. If necessary, command may # be used to specify where the compiler is located. The parameter 'options' is a @@ -668,6 +671,16 @@ class gcc-linking-generator : unix-linking-generator } local properties = [ $(property-set).raw ] ; + + # get all the linker-scripts + local .linker-scripts = [ $(property-set).get ] ; + for local ld in $(.linker-scripts) + { + # and now add them as linkflags + local tmp = [ $(ld).name ] ; + property-set = [ $(property-set).add-raw -T$(tmp) $(ld) ] ; + } + local reason ; if $(no-static-link) && static in $(properties) { @@ -689,6 +702,7 @@ class gcc-linking-generator : unix-linking-generator } } } + if $(reason) { ECHO warning: $(reason) ; diff --git a/test/gcc_runtime.py b/test/gcc_runtime.py index bc56eae9fd..73456e00ca 100644 --- a/test/gcc_runtime.py +++ b/test/gcc_runtime.py @@ -12,7 +12,10 @@ t = BoostBuild.Tester() t.write("jamroot.jam", "lib hello : hello.cpp ;") -t.write("hello.cpp", "int main() {}\n") +t.write("hello.cpp", "extern \"C\" int i; int main() { i = 42; return 0;}\n") +t.write("script.ld", "i = 42") + +# Also testing linker-scripts. If that thing works, the extern "C" int i can be resolved, elsewise not. t.run_build_system(["runtime-link=static"]) t.expect_output_lines("warning: On gcc, DLLs can not be built with " From 51a13af4e31653e0b6d5c22e57b5bd46b80cc33f Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Thu, 3 Mar 2016 20:27:29 +0100 Subject: [PATCH 2/8] fixed the dependency of gcc linker scripts. --- src/tools/gcc.jam | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/tools/gcc.jam b/src/tools/gcc.jam index 67bd135054..cd7cd9af69 100644 --- a/src/tools/gcc.jam +++ b/src/tools/gcc.jam @@ -672,15 +672,6 @@ class gcc-linking-generator : unix-linking-generator local properties = [ $(property-set).raw ] ; - # get all the linker-scripts - local .linker-scripts = [ $(property-set).get ] ; - for local ld in $(.linker-scripts) - { - # and now add them as linkflags - local tmp = [ $(ld).name ] ; - property-set = [ $(property-set).add-raw -T$(tmp) $(ld) ] ; - } - local reason ; if $(no-static-link) && static in $(properties) { @@ -715,6 +706,20 @@ class gcc-linking-generator : unix-linking-generator $(property-set) : $(sources) ] ; } } + rule generated-targets ( sources + : property-set : project name ? ) + { + # get all the linker-scripts + local .linker-scripts = [ $(property-set).get ] ; + for local ld in $(.linker-scripts) + { + # and now add them as linkflags + local tmp = [ $(ld).name ] ; + property-set = [ $(property-set).add-raw -T$(tmp) $(ld) ] ; + } + + + return [ unix-linking-generator.generated-targets $(sources) : $(property-set) : $(project) $(name) ] ; + } } # The set of permissible input types is different on mingw. So, define two sets From 585c350e2dda601cbc73226acfe5498eafaa56c0 Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Thu, 3 Mar 2016 21:28:24 +0100 Subject: [PATCH 3/8] added outline reader for msvc and gcc. also allows it with the standard command on unix --- doc/src/reference.xml | 10 ++++++++++ src/tools/gcc.jam | 22 ++++++++++++++++++++++ src/tools/msvc.jam | 15 +++++++++++++++ src/tools/unix.jam | 16 +++++++++++++++- test/gcc_runtime.py | 2 +- 5 files changed, 63 insertions(+), 2 deletions(-) diff --git a/doc/src/reference.xml b/doc/src/reference.xml index 609a3272f2..32e51af13c 100644 --- a/doc/src/reference.xml +++ b/doc/src/reference.xml @@ -286,7 +286,11 @@ path-constant DATA : data/a.txt ; This rule is deprecated and equivalent to alias. + + outline + Reads the outline of a binary and writes it into the file. + @@ -982,7 +986,13 @@ using gcc : &toolset_ops; ; Specifies a linker script to be used for linking. Several are allowed and each file must have the extension .ld + + demangle + + Can be used to enable demangled when reading the outline. + + 64-bit compilation diff --git a/src/tools/gcc.jam b/src/tools/gcc.jam index cd7cd9af69..cd0631e4f6 100644 --- a/src/tools/gcc.jam +++ b/src/tools/gcc.jam @@ -53,6 +53,9 @@ type.set-generated-target-suffix OBJ : gcc cygwin : o ; feature.feature linker-script : : free dependency ; type.register LINKERSCRIPT : ld : gcc ; + + + # Initializes the gcc toolset for the given version. If necessary, command may # be used to specify where the compiler is located. The parameter 'options' is a # space-delimited list of options, each one specified as @@ -275,6 +278,19 @@ rule init ( version ? : command * : options * ) rc-type = null ; } rc.configure $(rc) : $(condition) : $(rc-type) ; + + # NM, outline read + local nm = [ common.get-invocation-command gcc + : [ .get-prog-name $(command-string) : nm : $(flavor) ] + : [ feature.get-values : $(options) ] + : $(bin) + : search-path ] ; + + if ! $(nm) + { + $(nm) = nm ; + } + toolset.flags gcc.outline .NM $(condition) : $(nm) ; } if [ os.name ] = NT @@ -1099,6 +1115,12 @@ local rule cpu-flags ( toolset variable : architecture : instruction-set + : } + +# Outline +actions outline { + $(.NM) $(>:T) $(DEMANGLE) > $(<:T) +} + # Set architecture/instruction-set options. # # x86 and compatible diff --git a/src/tools/msvc.jam b/src/tools/msvc.jam index 78e64e6849..de82549d2e 100644 --- a/src/tools/msvc.jam +++ b/src/tools/msvc.jam @@ -111,6 +111,7 @@ rule init ( # # # + # # # # @@ -501,6 +502,10 @@ actions compile.rc $(.RC) -l 0x409 -U$(UNDEFS) -D$(DEFINES) -I"$(INCLUDES:W)" -fo "$(<:W)" "$(>:W)" } +actions outline +{ + $(.DUMPBIN) $(>:W) /RELOCATIONS > $(<:W) +} rule link ( targets + : sources * : properties * ) { @@ -1128,9 +1133,14 @@ local rule configure-really ( version ? : options * ) manifest-tool = [ feature.get-values : $(options) ] ; manifest-tool ?= mt ; + dumpbin = [ feature.get-values : $(options) ] ; + dumpbin ?= dumpbin ; + local cc-filter = [ feature.get-values : $(options) ] ; + + for local c in $(cpu) { # Setup script is not required in some configurations. @@ -1153,6 +1163,7 @@ local rule configure-really ( version ? : options * ) toolset.flags msvc.compile .IDL $(api)/$(cpu-conditions) : $(setup-$(c))$(idl-compiler) ; toolset.flags msvc.compile .MC $(api)/$(cpu-conditions) : $(setup-$(c))$(mc-compiler) ; toolset.flags msvc.link .MT $(api)/$(cpu-conditions) : $(setup-$(c))$(manifest-tool) -nologo ; + toolset.flags msvc.outline .DUMPBIN $(api)/$(cpu-conditions) : $(setup-$(c))$(dumpbin) ; for api in desktop store phone { @@ -1385,6 +1396,10 @@ local rule register-toolset-really ( ) generators.register [ new msvc-pch-generator msvc.compile.c.pch : H : C_PCH OBJ : on msvc ] ; generators.register [ new msvc-pch-generator msvc.compile.c++.pch : H : CPP_PCH OBJ : on msvc ] ; + generators.register-standard msvc.outline : LIB : OUTLINE : msvc ; + generators.register-standard msvc.outline : EXE : OUTLINE : msvc ; + generators.register-standard msvc.outline : OBJ : OUTLINE : msvc ; + generators.override msvc.compile.c.pch : pch.default-c-pch-generator ; generators.override msvc.compile.c++.pch : pch.default-cpp-pch-generator ; } diff --git a/src/tools/unix.jam b/src/tools/unix.jam index 75949851a0..095a67aa8c 100644 --- a/src/tools/unix.jam +++ b/src/tools/unix.jam @@ -15,6 +15,14 @@ import type ; import set ; import order ; import builtin ; +import toolset ; + + +# used for nm +feature.feature demangle : off on : propagated ; + + +toolset.flags unix.outline DEMANGLE on : --demangle ; class unix-linking-generator : linking-generator { @@ -155,6 +163,9 @@ generators.register [ new unix-searched-lib-generator unix.searched-lib-generator : : SEARCHED_LIB : unix ] ; +generators.register-standard unix.outline : LIB OBJ EXE : OUTLINE : unix ; + + # The derived toolset must specify their own actions. actions link { } @@ -171,7 +182,10 @@ actions searched-lib-generator { actions prebuilt { } - +# simple implementation here, because clang also uses nm. +actions outline { + nm $(>:T) $(DEMANGLE) > $(<:T) +} diff --git a/test/gcc_runtime.py b/test/gcc_runtime.py index 73456e00ca..bcf97d4e9d 100644 --- a/test/gcc_runtime.py +++ b/test/gcc_runtime.py @@ -11,7 +11,7 @@ import BoostBuild t = BoostBuild.Tester() -t.write("jamroot.jam", "lib hello : hello.cpp ;") +t.write("jamroot.jam", "lib hello : hello.cpp ; outline mangled : hello ; outline demangled : hello : on ;") t.write("hello.cpp", "extern \"C\" int i; int main() { i = 42; return 0;}\n") t.write("script.ld", "i = 42") From c8bc7f7e922932d20ec36296126667a798acf4a4 Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Thu, 3 Mar 2016 21:50:53 +0100 Subject: [PATCH 4/8] fixed outline by declaring it as composing --- src/tools/gcc.jam | 2 +- src/tools/msvc.jam | 4 +--- src/tools/unix.jam | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/tools/gcc.jam b/src/tools/gcc.jam index cd0631e4f6..21a8d8a323 100644 --- a/src/tools/gcc.jam +++ b/src/tools/gcc.jam @@ -1118,7 +1118,7 @@ local rule cpu-flags ( toolset variable : architecture : instruction-set + : # Outline actions outline { - $(.NM) $(>:T) $(DEMANGLE) > $(<:T) + $(.NM) $(DEMANGLE) $(>:T) > $(<:T) } # Set architecture/instruction-set options. diff --git a/src/tools/msvc.jam b/src/tools/msvc.jam index de82549d2e..3e498be895 100644 --- a/src/tools/msvc.jam +++ b/src/tools/msvc.jam @@ -1396,9 +1396,7 @@ local rule register-toolset-really ( ) generators.register [ new msvc-pch-generator msvc.compile.c.pch : H : C_PCH OBJ : on msvc ] ; generators.register [ new msvc-pch-generator msvc.compile.c++.pch : H : CPP_PCH OBJ : on msvc ] ; - generators.register-standard msvc.outline : LIB : OUTLINE : msvc ; - generators.register-standard msvc.outline : EXE : OUTLINE : msvc ; - generators.register-standard msvc.outline : OBJ : OUTLINE : msvc ; + generators.register-composing msvc.outline : LIB OBJ EXE : OUTLINE : msvc ; generators.override msvc.compile.c.pch : pch.default-c-pch-generator ; generators.override msvc.compile.c++.pch : pch.default-cpp-pch-generator ; diff --git a/src/tools/unix.jam b/src/tools/unix.jam index 095a67aa8c..adc01e5096 100644 --- a/src/tools/unix.jam +++ b/src/tools/unix.jam @@ -163,7 +163,7 @@ generators.register [ new unix-searched-lib-generator unix.searched-lib-generator : : SEARCHED_LIB : unix ] ; -generators.register-standard unix.outline : LIB OBJ EXE : OUTLINE : unix ; +generators.register-composing unix.outline : LIB EXE OBJ : OUTLINE : unix ; # The derived toolset must specify their own actions. @@ -184,7 +184,7 @@ actions prebuilt { # simple implementation here, because clang also uses nm. actions outline { - nm $(>:T) $(DEMANGLE) > $(<:T) + nm $(DEMANGLE) $(>:T) > $(<:T) } From 874c74002e19661953035582db92cbf0eaf4f107 Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Thu, 3 Mar 2016 22:00:37 +0100 Subject: [PATCH 5/8] added missing outline.jam --- src/tools/types/outline.jam | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/tools/types/outline.jam diff --git a/src/tools/types/outline.jam b/src/tools/types/outline.jam new file mode 100644 index 0000000000..d630c2cf4c --- /dev/null +++ b/src/tools/types/outline.jam @@ -0,0 +1,8 @@ +# Copyright Klemens D. Morgenstern 2016. Distributed under the Boost +# Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +import type ; + +type.register OUTLINE ; + From ffced4fcd94d343b874cf2bcc0f6d089a65efe2b Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Thu, 3 Mar 2016 22:14:12 +0100 Subject: [PATCH 6/8] changed target in jamroot to exe --- test/gcc_runtime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gcc_runtime.py b/test/gcc_runtime.py index bcf97d4e9d..4b82554cf5 100644 --- a/test/gcc_runtime.py +++ b/test/gcc_runtime.py @@ -11,7 +11,7 @@ import BoostBuild t = BoostBuild.Tester() -t.write("jamroot.jam", "lib hello : hello.cpp ; outline mangled : hello ; outline demangled : hello : on ;") +t.write("jamroot.jam", "exe hello : hello.cpp ; outline mangled : hello ; outline demangled : hello : on ;") t.write("hello.cpp", "extern \"C\" int i; int main() { i = 42; return 0;}\n") t.write("script.ld", "i = 42") From c6aa4f6c5a1afcdce35476c1225a4dd816ca0385 Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Thu, 3 Mar 2016 22:30:15 +0100 Subject: [PATCH 7/8] still trying to get the outline to work. --- test/gcc_runtime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gcc_runtime.py b/test/gcc_runtime.py index 4b82554cf5..9e0707d707 100644 --- a/test/gcc_runtime.py +++ b/test/gcc_runtime.py @@ -11,7 +11,7 @@ import BoostBuild t = BoostBuild.Tester() -t.write("jamroot.jam", "exe hello : hello.cpp ; outline mangled : hello ; outline demangled : hello : on ;") +t.write("jamroot.jam", "exe hello : hello.cpp ; outline mangled : hello ;") t.write("hello.cpp", "extern \"C\" int i; int main() { i = 42; return 0;}\n") t.write("script.ld", "i = 42") From ecc1beda4da4a5f87b0606f43c115cc53a3eae7c Mon Sep 17 00:00:00 2001 From: klemens-morgenstern Date: Thu, 3 Mar 2016 22:49:21 +0100 Subject: [PATCH 8/8] added size and objcopy I tested that locally (windows 10, arm-none-eabi-gcc 5.2) but cannot test that with a standard gcc --- src/tools/gcc.jam | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/tools/gcc.jam b/src/tools/gcc.jam index 21a8d8a323..f60a39f68b 100644 --- a/src/tools/gcc.jam +++ b/src/tools/gcc.jam @@ -53,6 +53,9 @@ type.set-generated-target-suffix OBJ : gcc cygwin : o ; feature.feature linker-script : : free dependency ; type.register LINKERSCRIPT : ld : gcc ; +# Add the size +type.register SIZE ; +type.register HEX : hex ; @@ -279,7 +282,7 @@ rule init ( version ? : command * : options * ) } rc.configure $(rc) : $(condition) : $(rc-type) ; - # NM, outline read + # NM, fg read local nm = [ common.get-invocation-command gcc : [ .get-prog-name $(command-string) : nm : $(flavor) ] : [ feature.get-values : $(options) ] @@ -291,6 +294,33 @@ rule init ( version ? : command * : options * ) $(nm) = nm ; } toolset.flags gcc.outline .NM $(condition) : $(nm) ; + + # Objsize create hexfile + local size = [ common.get-invocation-command gcc + : [ .get-prog-name $(command-string) : size : $(flavor) ] + : [ feature.get-values : $(options) ] + : $(bin) + : search-path ] ; + + if ! $(size) + { + $(size) = size ; + } + toolset.flags gcc.objsize .SIZE $(condition) : $(size) ; + + # Objcopy, create hexfile + local objcopy = [ common.get-invocation-command gcc + : [ .get-prog-name $(command-string) : objcopy : $(flavor) ] + : [ feature.get-values : $(options) ] + : $(bin) + : search-path ] ; + + if ! $(objcopy) + { + $(objcopy) = objcopy ; + } + toolset.flags gcc.objcopy .OBJCOPY $(condition) : $(objcopy) ; + toolset.flags gcc.objcopy .SIZE $(condition) : $(size) ; } if [ os.name ] = NT @@ -321,6 +351,10 @@ generators.register-c-compiler gcc.compile.c : C : OBJ : gcc ; generators.register-c-compiler gcc.compile.asm : ASM : OBJ : gcc ; generators.register-fortran-compiler gcc.compile.fortran : FORTRAN FORTRAN90 : OBJ : gcc ; + +generators.register-standard gcc.objcopy : EXE : HEX : gcc ; +generators.register-standard gcc.objsize : EXE : SIZE : gcc ; + # pch support # The compiler looks for a precompiled header in each directory just before it @@ -1121,6 +1155,20 @@ actions outline { $(.NM) $(DEMANGLE) $(>:T) > $(<:T) } + +# Objcopy +actions objcopy +{ + $(.OBJCOPY) ./$(>:T) ./$(<:T) + $(.SIZE) ./$(>:T) +} + +# Obj size +actions objsize +{ + $(.SIZE) ./$(>:T) > ./$(<:T) +} + # Set architecture/instruction-set options. # # x86 and compatible