File tree Expand file tree Collapse file tree 9 files changed +87
-84
lines changed Expand file tree Collapse file tree 9 files changed +87
-84
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,8 @@ SOURCES += main.cpp\
54
54
common.cpp \
55
55
fasm.cpp \
56
56
signallocker.cpp \
57
- masm.cpp
57
+ masm.cpp \
58
+ gccbasedassembler.cpp
58
59
59
60
HEADERS += mainwindow.h \
60
61
tab.h \
@@ -74,7 +75,8 @@ HEADERS += mainwindow.h \
74
75
common.h \
75
76
fasm.h \
76
77
signallocker.h \
77
- masm.h
78
+ masm.h \
79
+ gccbasedassembler.h
78
80
79
81
FORMS += settings.ui
80
82
Original file line number Diff line number Diff line change 46
46
*/
47
47
48
48
FASM::FASM (bool x86, QObject *parent) :
49
- Assembler (x86, parent)
49
+ GccBasedAssembler (x86, parent)
50
50
{
51
51
}
52
52
@@ -59,18 +59,6 @@ QString FASM::getAssemblerPath()
59
59
#endif
60
60
}
61
61
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
-
74
62
QString FASM::getListingFilePath (QFile &lstOut)
75
63
{
76
64
QString listingPath = Common::pathInTemp (" fasmListing.txt" );
@@ -211,16 +199,6 @@ QString FASM::getAssemblerOptions()
211
199
return " $SOURCE$ $PROGRAM.OBJ$ -s $LSTOUTPUT$" ;
212
200
}
213
201
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
-
224
202
void FASM::fillHighligherRules (QVector<Assembler::HighlightingRule> &highlightingRules,
225
203
QList<QTextCharFormat *> &formats,
226
204
bool &multiLineComments,
Original file line number Diff line number Diff line change 43
43
44
44
#include < QProcess>
45
45
#include < QLinkedList>
46
- #include " assembler .h"
46
+ #include " gccbasedassembler .h"
47
47
48
48
/* *
49
49
* @file fasm.h
55
55
*
56
56
*/
57
57
58
- class FASM : public Assembler
58
+ class FASM : public GccBasedAssembler
59
59
{
60
60
Q_OBJECT
61
61
public:
62
62
explicit FASM (bool x86, QObject *parent = 0 );
63
63
QString getAssemblerPath ();
64
- QString getLinkerPath ();
65
64
quint64 getMainOffset (QFile &lstOut, QString entryLabel);
66
65
void parseLstFile (QFile &lstOut, QVector<Assembler::LineNum> &lines, quint64 offset);
67
66
void fillHighligherRules (QVector<Assembler::HighlightingRule> &highlightingRules,
@@ -72,7 +71,6 @@ class FASM : public Assembler
72
71
QString getStartText ();
73
72
void putDebugString (CodeEditor *code);
74
73
QString getAssemblerOptions ();
75
- QString getLinkerOptions ();
76
74
QString getListingFilePath (QFile &lstOut);
77
75
78
76
signals:
Original file line number Diff line number Diff line change 46
46
*/
47
47
48
48
GAS::GAS (bool x86, QObject *parent) :
49
- Assembler (x86, parent)
49
+ GccBasedAssembler (x86, parent)
50
50
{
51
51
}
52
52
@@ -62,18 +62,6 @@ QString GAS::getAssemblerPath()
62
62
#endif
63
63
}
64
64
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
-
77
65
quint64 GAS::getMainOffset (QFile &lst, QString entryLabel)
78
66
{
79
67
QTextStream lstStream (&lst);
@@ -209,15 +197,6 @@ QString GAS::getAssemblerOptions()
209
197
return options;
210
198
}
211
199
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
- }
221
200
222
201
void GAS::fillHighligherRules (QVector<Assembler::HighlightingRule> &highlightingRules,
223
202
QList<QTextCharFormat *> &formats,
Original file line number Diff line number Diff line change 41
41
#ifndef GAS_H
42
42
#define GAS_H
43
43
44
- #include " assembler .h"
44
+ #include " gccbasedassembler .h"
45
45
46
46
/* *
47
47
* @file gas.h
52
52
*
53
53
*/
54
54
55
- class GAS : public Assembler
55
+ class GAS : public GccBasedAssembler
56
56
{
57
57
Q_OBJECT
58
58
public:
59
59
explicit GAS (bool x86, QObject *parent = 0 );
60
60
QString getAssemblerPath ();
61
- QString getLinkerPath ();
62
61
quint64 getMainOffset (QFile &lst, QString entryLabel);
63
62
void parseLstFile (QFile &lst, QVector<Assembler::LineNum> &lines, quint64 offset);
64
63
void fillHighligherRules (QVector<Assembler::HighlightingRule> &highlightingRules,
@@ -68,9 +67,7 @@ class GAS : public Assembler
68
67
QRegExp &commentEndExpression);
69
68
QString getStartText ();
70
69
void putDebugString (CodeEditor *code);
71
- QString getAssemblerOptions ();
72
- QString getLinkerOptions ();
73
-
70
+ QString getAssemblerOptions ();
74
71
signals:
75
72
76
73
public slots:
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 46
46
*/
47
47
48
48
NASM::NASM (bool x86, QObject *parent) :
49
- Assembler (x86, parent)
49
+ GccBasedAssembler (x86, parent)
50
50
{
51
51
}
52
52
@@ -59,17 +59,6 @@ QString NASM::getAssemblerPath()
59
59
#endif
60
60
}
61
61
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
- }
73
62
74
63
quint64 NASM::getMainOffset (QFile &lst, QString entryLabel)
75
64
{
@@ -219,16 +208,6 @@ QString NASM::getAssemblerOptions()
219
208
return options;
220
209
}
221
210
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
-
232
211
void NASM::fillHighligherRules (QVector<Assembler::HighlightingRule> &highlightingRules,
233
212
QList<QTextCharFormat *> &formats,
234
213
bool &multiLineComments,
Original file line number Diff line number Diff line change 41
41
#ifndef NASM_H
42
42
#define NASM_H
43
43
44
- #include " assembler .h"
44
+ #include " gccbasedassembler .h"
45
45
46
46
/* *
47
47
* @file nasm.h
52
52
*
53
53
*/
54
54
55
- class NASM : public Assembler
55
+ class NASM : public GccBasedAssembler
56
56
{
57
57
Q_OBJECT
58
58
public:
59
59
explicit NASM (bool x86, QObject *parent = 0 );
60
60
QString getAssemblerPath ();
61
- QString getLinkerPath ();
62
61
quint64 getMainOffset (QFile &lst, QString entryLabel);
63
62
void parseLstFile (QFile &lst, QVector<Assembler::LineNum> &lines, quint64 offset);
64
63
void fillHighligherRules (QVector<Assembler::HighlightingRule> &highlightingRules,
@@ -69,8 +68,7 @@ class NASM : public Assembler
69
68
QString getStartText ();
70
69
void putDebugString (CodeEditor *code);
71
70
QString getAssemblerOptions ();
72
- QString getLinkerOptions ();
73
-
71
+
74
72
signals:
75
73
76
74
public slots:
You can’t perform that action at this time.
0 commit comments