Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Warning

This is an unapproved draft. It is currently under review.

7.1 Introduction

rce modules and binary objects for host systems are compiled and linked with the gnu compiler and binutils collections. The build tool is gmake.

...

The reader is assumed to be familiar with the tools in the gnu collection.

Anchor
general
general

7.2 General compilation and linking requirements

While naturally the build system automates much of the compilation and linking process, developers must manage build dependencies manually, setting up makefiles such that modules and objects "lower" on the dependency graph are built before those "higher" on the graph.

...

TBW.

Anchor
hierarchy
hierarchy

7.3 Makefile and build product hierarchy

Source code in the rce repository is organized using a two-level structure in which projects contain one or more packages. Packages contain code and makefiles for the construction of one or more constituents.

...

Directory structure for rce build products

Anchor
globals
globals

7.4 Global make variables

-Under construction-

The repository-level makefiles define a set of global make variables that can be useful to cite in package- and constituent-level makefiles, and which set compiler options for various targets.

...

objdir
libdir
bindir

Anchor
constituent
constituent

7.5 Constituent makefiles

This section describes the most common make rules and option flags for building constituents.

...

Constituent make rules for host objects

TBW.

Anchor
project
project

7.6 Packages and project makefiles

This section describes the most common make rules and option flags for packages.mk and project.mk. See Chapter Z for definitions of all options.

Use application-specific files
projects.mk at top level
packages.mk for projects

Anchor
examples
examples

7.7 Make examples

gmake is invoked as follows:

...

Code Block
// change directory to top of release tree
prompt> gmake rceapp.console.ppc-rtems-rce405.obj

Anchor
options
options

7.8 Make invocation options

Path specification

gmake can be invoked at the release, project, or package level.

...

Make rule

Description

all

Build 'bin' and user-defined

dir

Create build directories, but do not build.

obj

Compile sources

lib

Build libraries from object files

bin

Build libraries, executables and modules

clean

Remove all built products

cleanall

Same as 'clean', but removes some tmp directories as well

print

List what is built and where it goes

Anchor
rcegcc
rcegcc

7.9 Compiler options for rce modules

The following compiler options are invoked via /make/sw/flags.mk. They are presented here for reference.
-shared
The linker will expect each module to have a "dynamic section" and a hash table for those symbols with global visibility.
-fno-pic
Although pic saves on relocations (one per function instead of one per function call) it requires the dynamic linker to know the special relocation types needed for the Global Offset Table and the Procedure Linkage Table. The latter is especially tricky to get right. It's simpler to use non-pic and just deal with the regular relocations.
The other usual reason to use pic (that most of the code can be mapped into multiple address spaces at the same time) doesn't apply here since rtems only offers one global address space.
-nostdlib
We supply our own module _init (rce_modinit) and module _fini (rce_modfinish) code. Another reason not to use the standard _init/_fini code is that their source code was compiled with -fpic.
-nostdlib also prevents searching of the standard C++ libraries. Instead we'll want to search the symbol table of the RTEMS+newlib executable either at the time the module is produced or at run time.
-fvisiblity=hidden
A shared object actually has two symbol tables, the normal one and a special "dynamic" table. The latter is the one that is searched in order to resolve inter-object references. In the past pretty much every non-static symbol from every object code file used to make the shared object went into the dynamic table. Since GCC 4.0 the compiler recognizes the -visibility option which controls the default visibility of symbols. Using -fvisibility=hidden makes "hidden" the default. Hidden symbols don't go into the dynamic symbol table so one can dramatically reduce its size. To make sure that the symbols associated with a variable, function or class do make it into the dynamic symbol table you need to mark it with _attribute_ ((visibility ("default"))):

...

Code Block
ifeq ($(tgt_cpu_family)-$(tgt_os),ppc-rtems)

AS  := powerpc-rtems-as
CPP := powerpc-rtems-cpp
CC  := powerpc-rtems-gcc
CXX := powerpc-rtems-g++
LD  := powerpc-rtems-ld
LX  := powerpc-rtems-g++

ifeq ($(tgt_board),rce405)
RTEMSDIR := $(RELEASE_DIR)/build/rtems/target/powerpc-rtems/rce405/lib
endif

ifeq ($(tgt_board),ml405)
RTEMSDIR := $(RELEASE_DIR)/build/rtems/target/powerpc-rtems/ml405/lib
endif

LDTOOLSD := $(RELEASE_DIR)/rce/ldtools
LIBEXTNS := a
DEPFLAGS := -B$(RTEMSDIR) -MM
DEFINES  += -Dppc405
CPPFLAGS :=
CFLAGS   := -B$(RTEMSDIR) -specs bsp_specs -qrtems -mcpu=403 -Wall
CXXFLAGS := $(CFLAGS)
CASFLAGS := -x assembler-with-cpp -P $(CFLAGS)
LDFLAGS  := -r
LXFLAGS  := -B$(RTEMSDIR) -specs $(LDTOOLSD)/dynamic_specs \
            -qrtems -qnolinkcmds -Wl,-T$(LDTOOLSD)/dynamic.ld \
            -mcpu=403
MANAGERS := timer sem msg event signal part region dpmem io rtmon ext mp

MDEFINES  := $(DEFINES)
             -DEXPORT='__attribute__((visibility("default")))'
MCFLAGS   := -B$(RTEMSDIR) -specs $(LDTOOLSD)/module_specs \
             -qrtems -Wall -fvisibility=hidden -mlongcall
             -fno-pic -mcpu=403
MCXXFLAGS := $(MCFLAGS)
MCASFLAGS := -x assembler-with-cpp -P $(MCFLAGS)
MLDFLAGS  := -r
MLXFLAGS  := -B$(RTEMSDIR) -specs $(LDTOOLSD)/module_specs \
             -qrtems -qnolinkcmds -Wl,-T$(LDTOOLSD)/module.ld-mcpu=403 \
             -shared -nostdlib

Anchor
rceld
rceld

7.10 gnu linker options for rce modules

The following gnu ld options are invoked via /make/sw/flags.mk. They are presented here for reference.

...