-
Notifications
You must be signed in to change notification settings - Fork 194
/
gccbasedassembler.cpp
62 lines (54 loc) · 1.54 KB
/
gccbasedassembler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "gccbasedassembler.h"
#include <QProcess>
#include <QProcessEnvironment>
#include <QStringList>
#ifndef Q_OS_WIN32
namespace
{
bool testPieOnUnix()
{
QProcess gccProcess;
QProcessEnvironment gccEnvironment = QProcessEnvironment::systemEnvironment();
QStringList gccArguments;
gccArguments << "-v";
gccEnvironment.insert("LC_MESSAGES", "en_US");
gccProcess.setProcessEnvironment(gccEnvironment);
gccProcess.start("gcc", gccArguments);
gccProcess.waitForFinished();
QString gccResult = QString(gccProcess.readAllStandardError());
return gccResult.indexOf("--enable-default-pie") != -1;
}
}
#endif
GccBasedAssembler::GccBasedAssembler(bool x86, QObject *parent)
: Assembler(x86, parent)
, m_isPieEnabled(false)
{
#ifndef Q_OS_WIN32
m_isPieEnabled = testPieOnUnix();
#endif
}
QString GccBasedAssembler::getLinkerPath()
{
#ifdef Q_OS_WIN32
if (isx86())
return Common::applicationDataPath() + "/MinGW/bin/gcc.exe";
else
return Common::applicationDataPath() + "/MinGW64/bin/gcc.exe";
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
return "/usr/bin/cc";
#else
return "gcc";
#endif
}
QString GccBasedAssembler::getLinkerOptions()
{
QString options;
if (isx86())
options = "$PROGRAM.OBJ$ $MACRO.OBJ$ -g -o $PROGRAM$ -m32";
else
options = "$PROGRAM.OBJ$ $MACRO.OBJ$ -g -o $PROGRAM$ -m64";
if (m_isPieEnabled)
options += " -no-pie";
return options;
}