Skip to content

Commit 107c7f9

Browse files
committed
[SASM-76] (-) Enable gcc pie detection
1 parent 308c525 commit 107c7f9

File tree

9 files changed

+87
-84
lines changed

9 files changed

+87
-84
lines changed

SASM.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ SOURCES += main.cpp\
5454
common.cpp \
5555
fasm.cpp \
5656
signallocker.cpp \
57-
masm.cpp
57+
masm.cpp \
58+
gccbasedassembler.cpp
5859

5960
HEADERS += mainwindow.h \
6061
tab.h \
@@ -74,7 +75,8 @@ HEADERS += mainwindow.h \
7475
common.h \
7576
fasm.h \
7677
signallocker.h \
77-
masm.h
78+
masm.h \
79+
gccbasedassembler.h
7880

7981
FORMS += settings.ui
8082

fasm.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*/
4747

4848
FASM::FASM(bool x86, QObject *parent) :
49-
Assembler(x86, parent)
49+
GccBasedAssembler(x86, parent)
5050
{
5151
}
5252

@@ -59,18 +59,6 @@ QString FASM::getAssemblerPath()
5959
#endif
6060
}
6161

62-
QString FASM::getLinkerPath()
63-
{
64-
#ifdef Q_OS_WIN32
65-
if (isx86())
66-
return Common::applicationDataPath() + "/MinGW/bin/gcc.exe";
67-
else
68-
return Common::applicationDataPath() + "/MinGW64/bin/gcc.exe";
69-
#else
70-
return "gcc";
71-
#endif
72-
}
73-
7462
QString FASM::getListingFilePath(QFile &lstOut)
7563
{
7664
QString listingPath = Common::pathInTemp("fasmListing.txt");
@@ -211,16 +199,6 @@ QString FASM::getAssemblerOptions()
211199
return "$SOURCE$ $PROGRAM.OBJ$ -s $LSTOUTPUT$";
212200
}
213201

214-
QString FASM::getLinkerOptions()
215-
{
216-
QString options;
217-
if (isx86())
218-
options = "$PROGRAM.OBJ$ -g -o $PROGRAM$ -m32";
219-
else
220-
options = "$PROGRAM.OBJ$ -g -o $PROGRAM$ -m64";
221-
return options;
222-
}
223-
224202
void FASM::fillHighligherRules(QVector<Assembler::HighlightingRule> &highlightingRules,
225203
QList<QTextCharFormat *> &formats,
226204
bool &multiLineComments,

fasm.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
#include <QProcess>
4545
#include <QLinkedList>
46-
#include "assembler.h"
46+
#include "gccbasedassembler.h"
4747

4848
/**
4949
* @file fasm.h
@@ -55,13 +55,12 @@
5555
*
5656
*/
5757

58-
class FASM : public Assembler
58+
class FASM : public GccBasedAssembler
5959
{
6060
Q_OBJECT
6161
public:
6262
explicit FASM(bool x86, QObject *parent = 0);
6363
QString getAssemblerPath();
64-
QString getLinkerPath();
6564
quint64 getMainOffset(QFile &lstOut, QString entryLabel);
6665
void parseLstFile(QFile &lstOut, QVector<Assembler::LineNum> &lines, quint64 offset);
6766
void fillHighligherRules(QVector<Assembler::HighlightingRule> &highlightingRules,
@@ -72,7 +71,6 @@ class FASM : public Assembler
7271
QString getStartText();
7372
void putDebugString(CodeEditor *code);
7473
QString getAssemblerOptions();
75-
QString getLinkerOptions();
7674
QString getListingFilePath(QFile &lstOut);
7775

7876
signals:

gas.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*/
4747

4848
GAS::GAS(bool x86, QObject *parent) :
49-
Assembler(x86, parent)
49+
GccBasedAssembler(x86, parent)
5050
{
5151
}
5252

@@ -62,18 +62,6 @@ QString GAS::getAssemblerPath()
6262
#endif
6363
}
6464

65-
QString GAS::getLinkerPath()
66-
{
67-
#ifdef Q_OS_WIN32
68-
if (isx86())
69-
return Common::applicationDataPath() + "/MinGW/bin/gcc.exe";
70-
else
71-
return Common::applicationDataPath() + "/MinGW64/bin/gcc.exe";
72-
#else
73-
return "gcc";
74-
#endif
75-
}
76-
7765
quint64 GAS::getMainOffset(QFile &lst, QString entryLabel)
7866
{
7967
QTextStream lstStream(&lst);
@@ -209,15 +197,6 @@ QString GAS::getAssemblerOptions()
209197
return options;
210198
}
211199

212-
QString GAS::getLinkerOptions()
213-
{
214-
QString options;
215-
if (isx86())
216-
options = "$PROGRAM.OBJ$ -g -o $PROGRAM$ -m32";
217-
else
218-
options = "$PROGRAM.OBJ$ -g -o $PROGRAM$ -m64";
219-
return options;
220-
}
221200

222201
void GAS::fillHighligherRules(QVector<Assembler::HighlightingRule> &highlightingRules,
223202
QList<QTextCharFormat *> &formats,

gas.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#ifndef GAS_H
4242
#define GAS_H
4343

44-
#include "assembler.h"
44+
#include "gccbasedassembler.h"
4545

4646
/**
4747
* @file gas.h
@@ -52,13 +52,12 @@
5252
*
5353
*/
5454

55-
class GAS : public Assembler
55+
class GAS : public GccBasedAssembler
5656
{
5757
Q_OBJECT
5858
public:
5959
explicit GAS(bool x86, QObject *parent = 0);
6060
QString getAssemblerPath();
61-
QString getLinkerPath();
6261
quint64 getMainOffset(QFile &lst, QString entryLabel);
6362
void parseLstFile(QFile &lst, QVector<Assembler::LineNum> &lines, quint64 offset);
6463
void fillHighligherRules(QVector<Assembler::HighlightingRule> &highlightingRules,
@@ -68,9 +67,7 @@ class GAS : public Assembler
6867
QRegExp &commentEndExpression);
6968
QString getStartText();
7069
void putDebugString(CodeEditor *code);
71-
QString getAssemblerOptions();
72-
QString getLinkerOptions();
73-
70+
QString getAssemblerOptions();
7471
signals:
7572

7673
public slots:

gccbasedassembler.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "gccbasedassembler.h"
2+
3+
#include <QProcess>
4+
#include <QProcessEnvironment>
5+
#include <QStringList>
6+
namespace
7+
{
8+
bool testPieOnUnix()
9+
{
10+
QProcess gccProcess;
11+
QProcessEnvironment gccEnvironment = QProcessEnvironment::systemEnvironment();
12+
QStringList gccArguments;
13+
gccArguments << "-v";
14+
gccEnvironment.insert("LC_MESSAGES", "en_US");
15+
gccProcess.setProcessEnvironment(gccEnvironment);
16+
gccProcess.start("gcc", gccArguments);
17+
gccProcess.waitForFinished();
18+
QString gccResult = QString(gccProcess.readAllStandardError());
19+
return gccResult.indexOf("--enable-default-pie") != -1;
20+
}
21+
}
22+
23+
GccBasedAssembler::GccBasedAssembler(bool x86, QObject *parent)
24+
: Assembler(x86, parent)
25+
, m_isPieEnabled(false)
26+
{
27+
#ifndef Q_OS_WIN32
28+
m_isPieEnabled = testPieOnUnix();
29+
#endif
30+
31+
}
32+
33+
34+
QString GccBasedAssembler::getLinkerPath()
35+
{
36+
#ifdef Q_OS_WIN32
37+
if (isx86())
38+
return Common::applicationDataPath() + "/MinGW/bin/gcc.exe";
39+
else
40+
return Common::applicationDataPath() + "/MinGW64/bin/gcc.exe";
41+
#else
42+
return "gcc";
43+
#endif
44+
}
45+
46+
QString GccBasedAssembler::getLinkerOptions()
47+
{
48+
QString options;
49+
if (isx86())
50+
options = "$PROGRAM.OBJ$ -g -o $PROGRAM$ -m32";
51+
else
52+
options = "$PROGRAM.OBJ$ -g -o $PROGRAM$ -m64";
53+
if (m_isPieEnabled)
54+
options += " -fno-pie -no-pie";
55+
return options;
56+
}
57+

gccbasedassembler.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef GCCBASEDASSEMBLER_H
2+
#define GCCBASEDASSEMBLER_H
3+
#include "assembler.h"
4+
5+
class GccBasedAssembler : public Assembler
6+
{
7+
public:
8+
explicit GccBasedAssembler(bool x86, QObject *parent = 0);
9+
QString getLinkerPath() override;
10+
QString getLinkerOptions() override;
11+
private:
12+
bool m_isPieEnabled;
13+
};
14+
15+
#endif // GCCBASEDASSEMBLER_H

nasm.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*/
4747

4848
NASM::NASM(bool x86, QObject *parent) :
49-
Assembler(x86, parent)
49+
GccBasedAssembler(x86, parent)
5050
{
5151
}
5252

@@ -59,17 +59,6 @@ QString NASM::getAssemblerPath()
5959
#endif
6060
}
6161

62-
QString NASM::getLinkerPath()
63-
{
64-
#ifdef Q_OS_WIN32
65-
if (isx86())
66-
return Common::applicationDataPath() + "/MinGW/bin/gcc.exe";
67-
else
68-
return Common::applicationDataPath() + "/MinGW64/bin/gcc.exe";
69-
#else
70-
return "gcc";
71-
#endif
72-
}
7362

7463
quint64 NASM::getMainOffset(QFile &lst, QString entryLabel)
7564
{
@@ -219,16 +208,6 @@ QString NASM::getAssemblerOptions()
219208
return options;
220209
}
221210

222-
QString NASM::getLinkerOptions()
223-
{
224-
QString options;
225-
if (isx86())
226-
options = "$PROGRAM.OBJ$ $MACRO.OBJ$ -g -o $PROGRAM$ -m32";
227-
else
228-
options = "$PROGRAM.OBJ$ $MACRO.OBJ$ -g -o $PROGRAM$ -m64";
229-
return options;
230-
}
231-
232211
void NASM::fillHighligherRules(QVector<Assembler::HighlightingRule> &highlightingRules,
233212
QList<QTextCharFormat *> &formats,
234213
bool &multiLineComments,

nasm.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#ifndef NASM_H
4242
#define NASM_H
4343

44-
#include "assembler.h"
44+
#include "gccbasedassembler.h"
4545

4646
/**
4747
* @file nasm.h
@@ -52,13 +52,12 @@
5252
*
5353
*/
5454

55-
class NASM : public Assembler
55+
class NASM : public GccBasedAssembler
5656
{
5757
Q_OBJECT
5858
public:
5959
explicit NASM(bool x86, QObject *parent = 0);
6060
QString getAssemblerPath();
61-
QString getLinkerPath();
6261
quint64 getMainOffset(QFile &lst, QString entryLabel);
6362
void parseLstFile(QFile &lst, QVector<Assembler::LineNum> &lines, quint64 offset);
6463
void fillHighligherRules(QVector<Assembler::HighlightingRule> &highlightingRules,
@@ -69,8 +68,7 @@ class NASM : public Assembler
6968
QString getStartText();
7069
void putDebugString(CodeEditor *code);
7170
QString getAssemblerOptions();
72-
QString getLinkerOptions();
73-
71+
7472
signals:
7573

7674
public slots:

0 commit comments

Comments
 (0)