Implement linkerscript element

svn path=/trunk/; revision=18758
This commit is contained in:
Casper Hornstrup 2005-10-24 19:38:58 +00:00
parent dd10647983
commit b995bcf1bd
6 changed files with 144 additions and 7 deletions

View file

@ -1417,12 +1417,18 @@ MingwModuleHandler::GenerateLinkerCommand (
{
string target ( GetTargetMacro ( module ) );
string target_folder ( GetDirectory ( GetTargetFilename ( module, NULL ) ) );
string def_file = GetDefinitionFilename ();
string definitionFilename = GetDefinitionFilename ();
string linkerScriptArgument;
if ( module.linkerScript != NULL )
linkerScriptArgument = ssprintf ( "-Wl,-T,%s", module.linkerScript->directory.c_str () );
else
linkerScriptArgument = "";
fprintf ( fMakefile,
"%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
target.c_str (),
def_file.c_str (),
definitionFilename.c_str (),
dependencies.c_str (),
target_folder.c_str () );
fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
@ -1432,19 +1438,20 @@ MingwModuleHandler::GenerateLinkerCommand (
{
string temp_exp = ros_temp + module.name + ".temp.exp";
CLEAN_FILE ( temp_exp );
string killAt = module.mangledSymbols ? "" : "--kill-at";
fprintf ( fMakefile,
"\t${dlltool} --dllname %s --def %s --output-exp %s %s\n",
targetName.c_str (),
def_file.c_str (),
definitionFilename.c_str (),
temp_exp.c_str (),
killAt.c_str () );
fprintf ( fMakefile,
"\t%s %s %s -o %s %s %s %s\n",
"\t%s %s %s -o %s %s %s %s %s\n",
linker.c_str (),
linkerParameters.c_str (),
linkerScriptArgument.c_str (),
temp_exp.c_str (),
target.c_str (),
objectsMacro.c_str (),
@ -1463,9 +1470,10 @@ MingwModuleHandler::GenerateLinkerCommand (
else
{
fprintf ( fMakefile,
"\t%s %s -o %s %s %s %s\n",
"\t%s %s -o %s %s %s %s %s\n",
linker.c_str (),
linkerParameters.c_str (),
linkerScriptArgument.c_str (),
target.c_str (),
objectsMacro.c_str (),
libsMacro.c_str (),

View file

@ -129,7 +129,7 @@ Value:
None.
Elements:
bootstrap, component, define, dependency, directory, file, if, importlibrary, include, invoke, library, property.
bootstrap, component, define, dependency, directory, file, if, importlibrary, include, invoke, library, linkerscript, property.
Module types
@ -466,6 +466,23 @@ Elements:
None.
Linkerscript
------------
A linkerscript element specifies the filename of a binutils linker script.
Syntax:
<linkerscript base="mymodule">MyLinkerScript</linkerscript>
Attributes:
base - Module which the value of this element is relative to. This attribute is optional. If left out, the linker script is relative to the position of the top-level xml build file.
Value:
Relative linker script filename.
Elements:
None.
Property
--------
A property element specifies the name and value of a property that can be used for conditional processing of the xml build file.

View file

@ -0,0 +1,73 @@
/*
* Copyright (C) 2005 Casper S. Hornstrup
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "pch.h"
#include <assert.h>
#include "rbuild.h"
using std::string;
using std::vector;
LinkerScript::LinkerScript ( const Project& project,
const Module* module,
const XMLElement& node )
: project ( project ),
module ( module ),
node ( node ),
baseModule ( NULL )
{
}
LinkerScript::~LinkerScript ()
{
}
void
LinkerScript::ProcessXML()
{
const XMLAttribute* att;
att = node.GetAttribute ( "base",
false );
if ( att )
{
bool referenceResolved = false;
if ( att->value == project.name )
{
basePath = ".";
referenceResolved = true;
}
else
{
const Module* base = project.LocateModule ( att->value );
if ( base != NULL )
{
baseModule = base;
basePath = base->GetBasePath ();
referenceResolved = true;
}
}
if ( !referenceResolved )
throw InvalidBuildFileException (
node.location,
"<linkerscript> attribute 'base' references non-existant project or module '%s'",
att->value.c_str() );
directory = NormalizeFilename ( basePath + SSEP + node.value );
}
else
directory = NormalizeFilename ( node.value );
}

View file

@ -211,6 +211,7 @@ Module::Module ( const Project& project,
node (moduleNode),
importLibrary (NULL),
bootstrap (NULL),
linkerScript (NULL),
pch (NULL),
cplusplus (false),
host (HostDefault)
@ -372,6 +373,8 @@ Module::~Module ()
delete linkerFlags[i];
for ( i = 0; i < stubbedComponents.size(); i++ )
delete stubbedComponents[i];
if ( linkerScript )
delete linkerScript;
if ( pch )
delete pch;
}
@ -409,6 +412,8 @@ Module::ProcessXML()
for ( i = 0; i < stubbedComponents.size(); i++ )
stubbedComponents[i]->ProcessXML();
non_if_data.ProcessXML();
if ( linkerScript )
linkerScript->ProcessXML();
if ( pch )
pch->ProcessXML();
}
@ -556,6 +561,15 @@ Module::ProcessXMLSubElement ( const XMLElement& e,
linkerFlags.push_back ( new LinkerFlag ( project, this, e ) );
subs_invalid = true;
}
else if ( e.name == "linkerscript" )
{
if ( linkerScript )
throw InvalidBuildFileException (
e.location,
"Only one <linkerscript> is valid per module" );
linkerScript = new LinkerScript ( project, this, e );
subs_invalid = true;
}
else if ( e.name == "component" )
{
stubbedComponents.push_back ( new StubbedComponent ( this, e ) );

View file

@ -73,6 +73,7 @@ class ImportLibrary;
class If;
class CompilerFlag;
class LinkerFlag;
class LinkerScript;
class Property;
class TestSupportCode;
class WineResource;
@ -230,6 +231,7 @@ public:
std::vector<CompilerFlag*> compilerFlags;
std::vector<LinkerFlag*> linkerFlags;
std::vector<StubbedComponent*> stubbedComponents;
LinkerScript* linkerScript;
PchFile* pch;
bool cplusplus;
std::string prefix;
@ -476,6 +478,24 @@ private:
};
class LinkerScript
{
public:
const Project& project;
const Module* module;
const XMLElement& node;
const Module* baseModule;
std::string directory;
std::string basePath;
LinkerScript ( const Project& project,
const Module* module,
const XMLElement& node );
~LinkerScript ();
void ProcessXML();
};
class Property
{
public:

View file

@ -163,6 +163,7 @@ RBUILD_COMMON_SOURCES = \
include.cpp \
installfile.cpp \
linkerflag.cpp \
linkerscript.cpp \
module.cpp \
project.cpp \
ssprintf.cpp \
@ -299,6 +300,10 @@ $(RBUILD_INT_)linkerflag.o: $(RBUILD_BASE_)linkerflag.cpp $(RBUILD_HEADERS) | $(
$(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
$(RBUILD_INT_)linkerscript.o: $(RBUILD_BASE_)linkerscript.cpp $(RBUILD_HEADERS) | $(RBUILD_INT)
$(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
$(RBUILD_INT_)module.o: $(RBUILD_BASE_)module.cpp $(RBUILD_HEADERS) | $(RBUILD_INT)
$(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@