Skip to content

Commit b478000

Browse files
committed
Improve linux linking.
1 parent 8197220 commit b478000

9 files changed

Lines changed: 208 additions & 162 deletions

File tree

src/sw/client/command/build.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ static sw::TargetSettings compilerTypeFromStringCaseI(const sw::UnresolvedPackag
113113
{
114114
ts["native"]["program"]["c"] = set_with_version("org.gnu.gcc");
115115
ts["native"]["program"]["cpp"] = set_with_version("org.gnu.gpp");
116-
ts["native"]["program"]["asm"] = set_with_version("org.gnu.gcc.as");
116+
ts["native"]["program"]["asm"] = set_with_version(ts["native"]["program"]["c"].getValue());
117117
}
118118
else if (compiler.ppath == "clang")
119119
{
120120
ts["native"]["program"]["c"] = set_with_version("org.LLVM.clang");
121121
ts["native"]["program"]["cpp"] = set_with_version("org.LLVM.clangpp");
122-
ts["native"]["program"]["asm"] = set_with_version("org.LLVM.clang"); // llvm-as?
122+
ts["native"]["program"]["asm"] = set_with_version(ts["native"]["program"]["c"].getValue());
123123
}
124124
// clang-cl is not possible for package path
125125
else if (compiler.ppath == "clangcl"/* || compiler.ppath == "clang-cl"*/)

src/sw/core/program/detect.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ void detectWindowsClang(DETECT_ARGS)
966966
auto &c = addProgram(s, PackageId("org.LLVM.clang", v), p);
967967
}
968968
auto c = p->getCommand();
969-
c->push_back("-Wno-everything");
969+
//c->push_back("-Wno-everything");
970970
// is it able to find VC STL itself?
971971
//COpts2.System.IncludeDirectories.insert(base_llvm_path / "lib" / "clang" / C->getVersion().toString() / "include");
972972
}
@@ -987,7 +987,7 @@ void detectWindowsClang(DETECT_ARGS)
987987
auto &c = addProgram(s, PackageId("org.LLVM.clangpp", v), p);
988988
}
989989
auto c = p->getCommand();
990-
c->push_back("-Wno-everything");
990+
//c->push_back("-Wno-everything");
991991
// is it able to find VC STL itself?
992992
//COpts2.System.IncludeDirectories.insert(base_llvm_path / "lib" / "clang" / C->getVersion().toString() / "include");
993993
}
@@ -1013,8 +1013,8 @@ void detectNonWindowsCompilers(DETECT_ARGS)
10131013
};
10141014

10151015
resolve_and_add("ar", "org.gnu.binutils.ar");
1016-
resolve_and_add("as", "org.gnu.gcc.as");
1017-
resolve_and_add("ld", "org.gnu.gcc.ld");
1016+
//resolve_and_add("as", "org.gnu.gcc.as"); // not needed
1017+
//resolve_and_add("ld", "org.gnu.gcc.ld"); // not needed
10181018

10191019
resolve_and_add("gcc", "org.gnu.gcc");
10201020
resolve_and_add("g++", "org.gnu.gpp");
@@ -1026,8 +1026,8 @@ void detectNonWindowsCompilers(DETECT_ARGS)
10261026
}
10271027

10281028
// llvm/clang
1029-
resolve_and_add("llvm-ar", "org.LLVM.ar");
1030-
resolve_and_add("lld", "org.LLVM.ld");
1029+
//resolve_and_add("llvm-ar", "org.LLVM.ar"); // not needed
1030+
//resolve_and_add("lld", "org.LLVM.ld"); // not needed
10311031

10321032
resolve_and_add("clang", "org.LLVM.clang");
10331033
resolve_and_add("clang++", "org.LLVM.clangpp");

src/sw/core/sw_context.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,39 @@ void SwCoreContext::setHostPrograms()
6868
else
6969
SW_UNIMPLEMENTED;
7070
}
71-
else if (getHostOs().is(OSType::Linux))
71+
// add more defaults
72+
else
7273
{
74+
// set default libs?
7375
/*ts["native"]["stdlib"]["c"] = "com.Microsoft.Windows.SDK.ucrt";
7476
ts["native"]["stdlib"]["cpp"] = "com.Microsoft.VisualStudio.VC.libcpp";
7577
ts["native"]["stdlib"]["kernel"] = "com.Microsoft.Windows.SDK.um";*/
7678

77-
auto if_add = [this](auto &s, const auto &name)
79+
auto if_add = [this](auto &s, const String &name)
7880
{
79-
if (getPredefinedTargets()[name].empty())
81+
auto &pd = getPredefinedTargets();
82+
auto i = pd.find(UnresolvedPackage(name));
83+
if (i == pd.end() || i->second.empty())
8084
return false;
8185
s = name;
8286
return true;
8387
};
8488

8589
//if_add(ts["native"]["program"]["c"], "org.gnu.gcc");
86-
if_add(ts["native"]["program"]["c"], "org.LLVM.clang");
90+
if_add(ts["native"]["program"]["c"], "org.LLVM.clang"s);
8791
//if_add(ts["native"]["program"]["cpp"], "org.gnu.gpp");
88-
if_add(ts["native"]["program"]["cpp"], "org.LLVM.clangpp");
92+
if_add(ts["native"]["program"]["cpp"], "org.LLVM.clangpp"s);
93+
94+
// using c prog
95+
if_add(ts["native"]["program"]["asm"], ts["native"]["program"]["c"].getValue());
8996

90-
if_add(ts["native"]["program"]["asm"], "org.gnu.gcc.as");
91-
if_add(ts["native"]["program"]["lib"], "org.gnu.binutils.ar");
92-
if_add(ts["native"]["program"]["link"], "org.gnu.gcc.ld");
97+
// reconsider, also with driver
98+
if_add(ts["native"]["program"]["lib"], "org.gnu.binutils.ar"s);
99+
100+
// use driver
101+
// use cpp driver for the moment to not burden ourselves in adding stdlib
102+
if_add(ts["native"]["program"]["link"], ts["native"]["program"]["cpp"].getValue());
93103
}
94-
// add more defaults
95-
else
96-
SW_UNIMPLEMENTED;
97104
}
98105

99106
TargetData &SwCoreContext::getTargetData(const PackageId &pkg)

src/sw/driver/compiler/compiler.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ static void add_args(driver::Command &c, const Strings &args)
4343
c.arguments.push_back(a);
4444
}
4545

46-
/*bool NativeToolchain::operator<(const NativeToolchain &rhs) const
47-
{
48-
SW_UNIMPLEMENTED;
49-
//return std::tie(LibrariesType, ConfigurationType, MT, SDK) <
50-
//std::tie(rhs.LibrariesType, rhs.ConfigurationType, rhs.MT, rhs.SDK);
51-
}
52-
53-
bool NativeToolchain::operator==(const NativeToolchain &rhs) const
54-
{
55-
SW_UNIMPLEMENTED;
56-
//return std::tie(LibrariesType, ConfigurationType, MT, SDK) ==
57-
//std::tie(rhs.LibrariesType, rhs.ConfigurationType, rhs.MT, rhs.SDK);
58-
}*/
59-
6046
CompilerBaseProgram::CompilerBaseProgram(const CompilerBaseProgram &rhs)
6147
: FileToFileTransformProgram(rhs)
6248
{
@@ -82,13 +68,6 @@ std::shared_ptr<builder::Command> CompilerBaseProgram::createCommand(const SwBui
8268
return cmd = createCommand1(swctx);
8369
}
8470

85-
/*std::shared_ptr<builder::Command> CompilerBaseProgram::createCommand(const std::shared_ptr<builder::Command> &c)
86-
{
87-
if (cmd)
88-
throw SW_RUNTIME_ERROR("Command already created");
89-
return cmd = c;
90-
}*/
91-
9271
std::shared_ptr<builder::Command> CompilerBaseProgram::getCommand(const Target &t)
9372
{
9473
prepareCommand(t);

src/sw/driver/compiler/compiler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ struct SW_DRIVER_CPP_API Linker : CompilerBaseProgram
330330
};
331331

332332
struct SW_DRIVER_CPP_API NativeLinker : Linker,
333-
NativeLinkerOptions//, OptionsGroup<NativeLinkerOptions>
333+
NativeLinkerOptions
334334
{
335335
LinkerType Type = LinkerType::UnspecifiedLinker;
336336

@@ -408,6 +408,8 @@ struct SW_DRIVER_CPP_API GNULibraryTool : GNU,
408408
virtual void getAdditionalOptions(driver::Command *c) const = 0;
409409
};
410410

411+
// we invoke linker via driver (gcc/clang)
412+
// so linker options are prefixed with -Wl,
411413
struct SW_DRIVER_CPP_API GNULinker : GNULibraryTool,
412414
CommandLineOptions<GNULinkerOptions>
413415
{

src/sw/driver/options_cl.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,16 @@ types:
900900
- ifiles
901901

902902
flags:
903+
nostdlib:
904+
name: nostdlib
905+
flag: nostdlib
906+
type: bool
907+
908+
nostartfiles:
909+
name: nostartfiles
910+
flag: nostartfiles
911+
type: bool
912+
903913
startfiles:
904914
name: StartFiles
905915
type: FilesOrdered
@@ -916,13 +926,13 @@ types:
916926

917927
sg:
918928
name: StartGroup
919-
flag: start-group
929+
flag: Wl,-start-group
920930
type: bool
921931
order: 50
922932

923933
eg:
924934
name: EndGroup
925-
flag: end-group
935+
flag: Wl,-end-group
926936
type: bool
927937
order: 70
928938

@@ -969,7 +979,8 @@ types:
969979

970980
undef:
971981
name: Undefined
972-
flag: undefined
982+
# gcc use only -u, not -undefined
983+
flag: u #undefined
973984
type: String
974985

975986
# ar

0 commit comments

Comments
 (0)