From: Casper Hornstrup Date: Mon, 24 Oct 2005 19:38:58 +0000 (+0000) Subject: Implement linkerscript element X-Git-Tag: backups/ros-branch-0_2_9@19949~1115 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=b995bcf1bd7dd56da85f0fdfffef53ddaa81e916 Implement linkerscript element svn path=/trunk/; revision=18758 --- diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp index 77cd792679e..64418896442 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp @@ -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 (), diff --git a/reactos/tools/rbuild/doc/rbuild.txt b/reactos/tools/rbuild/doc/rbuild.txt index a615b088f55..b514b69dc2a 100644 --- a/reactos/tools/rbuild/doc/rbuild.txt +++ b/reactos/tools/rbuild/doc/rbuild.txt @@ -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: + MyLinkerScript + +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. diff --git a/reactos/tools/rbuild/linkerscript.cpp b/reactos/tools/rbuild/linkerscript.cpp new file mode 100644 index 00000000000..955b8cfc691 --- /dev/null +++ b/reactos/tools/rbuild/linkerscript.cpp @@ -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 + +#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, + " attribute 'base' references non-existant project or module '%s'", + att->value.c_str() ); + directory = NormalizeFilename ( basePath + SSEP + node.value ); + } + else + directory = NormalizeFilename ( node.value ); +} diff --git a/reactos/tools/rbuild/module.cpp b/reactos/tools/rbuild/module.cpp index bd492bfa391..8bf14653653 100644 --- a/reactos/tools/rbuild/module.cpp +++ b/reactos/tools/rbuild/module.cpp @@ -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 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 ) ); diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index 87992f1cc04..1f1a1918d94 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -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 compilerFlags; std::vector linkerFlags; std::vector 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: diff --git a/reactos/tools/rbuild/rbuild.mak b/reactos/tools/rbuild/rbuild.mak index 8ad02644ccf..cde64588801 100644 --- a/reactos/tools/rbuild/rbuild.mak +++ b/reactos/tools/rbuild/rbuild.mak @@ -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 $@