From 0f7867524bf87a389ff5d4f9d3290d68a254b693 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 6 Oct 2014 02:49:06 +0300 Subject: [PATCH] Don't rely on component type in determining whether to use -fPIC Instead let SharedLibrary set a flag in ObjectFiles and use that. --- source/gnucompiler.cpp | 2 +- source/objectfile.cpp | 8 +++++++- source/objectfile.h | 4 ++++ source/sharedlibrary.cpp | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 1b05a5c..a86cb59 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -151,7 +151,7 @@ Task *GnuCompiler::run(const Target &target) const } if(binfo.threads && architecture->get_system()!="windows" && architecture->get_system()!="darwin") argv.push_back("-pthread"); - if((comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE) && architecture->get_system()!="windows") + if(object.is_used_in_shared_library() && architecture->get_system()!="windows") argv.push_back("-fPIC"); const Architecture &native_arch = builder.get_native_arch(); diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 732fe14..0536755 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -11,7 +11,8 @@ using namespace Msp; ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s): FileTarget(b, c.get_package(), generate_target_path(c, s.get_path())), - source(s) + source(s), + used_in_shlib(false) { component = &c; add_dependency(source); @@ -37,6 +38,11 @@ FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path return temp_dir/(FS::basepart(fn)+".o"); } +void ObjectFile::set_used_in_shared_library(bool u) +{ + used_in_shlib = u; +} + void ObjectFile::collect_build_info(BuildInfo &binfo) const { Target::collect_build_info(binfo); diff --git a/source/objectfile.h b/source/objectfile.h index 1546a56..48e4482 100644 --- a/source/objectfile.h +++ b/source/objectfile.h @@ -12,6 +12,7 @@ class ObjectFile: public FileTarget { private: SourceFile &source; + bool used_in_shlib; public: ObjectFile(Builder &, const Component &, SourceFile &); @@ -22,6 +23,9 @@ public: virtual const char *get_type() const { return "ObjectFile"; } SourceFile &get_source() const { return source; } + void set_used_in_shared_library(bool); + bool is_used_in_shared_library() const { return used_in_shlib; } + virtual void collect_build_info(BuildInfo &) const; private: diff --git a/source/sharedlibrary.cpp b/source/sharedlibrary.cpp index ae44f2c..305061a 100644 --- a/source/sharedlibrary.cpp +++ b/source/sharedlibrary.cpp @@ -2,6 +2,7 @@ #include #include "builder.h" #include "component.h" +#include "objectfile.h" #include "sharedlibrary.h" #include "sourcepackage.h" @@ -48,6 +49,9 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list::const_iterator i=objects.begin(); i!=objects.end(); ++i) + (*i)->set_used_in_shared_library(true); } string SharedLibrary::generate_filename(const Component &comp) -- 2.45.2