Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
smol
Commits
434630e6
Commit
434630e6
authored
Mar 06, 2019
by
PoroCYon
Committed by
PoroCYon
Mar 14, 2019
Browse files
fix -fno-plt failing
parent
1e553444
Changes
4
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
434630e6
...
@@ -7,11 +7,14 @@ TESTDIR:= test
...
@@ -7,11 +7,14 @@ TESTDIR:= test
BITS
?=
$(
shell
getconf LONG_BIT
)
BITS
?=
$(
shell
getconf LONG_BIT
)
# -mpreferred-stack-boundary=3 messes up the stack and kills SSE!
# -mpreferred-stack-boundary=3 messes up the stack and kills SSE!
# -fno-plt
#COPTFLAGS=-Os -fvisibility=hidden -fwhole-program -fno-plt \
COPTFLAGS
=
-Os
-fvisibility
=
hidden
-fwhole-program
-fno-plt
\
# -ffast-math -funsafe-math-optimizations -fno-stack-protector -fomit-frame-pointer \
-ffast-math
-funsafe-math-optimizations
-fno-stack-protector
-fomit-frame-pointer
\
# -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables
-fno-exceptions
-fno-unwind-tables
-fno-asynchronous-unwind-tables
CXXOPTFLAGS
=
$(COPTFLAGS)
\
COPTFLAGS
=
-O2
-fno-plt
-fno-stack-protector
-fno-stack-check
-fno-unwind-tables
\
-fno-asynchronous-unwind-tables
-fomit-frame-pointer
-ffast-math
-no-pie
\
-fno-pic
-fno-PIE
-m64
-march
=
core2
-ffunction-sections
-fdata-sections
CXXOPTFLAGS
=
$(COPTFLAGS)
-fno-exceptions
\
-fno-rtti
-fno-enforce-eh-specs
-fnothrow-opt
-fno-use-cxa-get-exception-ptr
\
-fno-rtti
-fno-enforce-eh-specs
-fnothrow-opt
-fno-use-cxa-get-exception-ptr
\
-fno-implicit-templates
-fno-threadsafe-statics
-fno-use-cxa-atexit
-fno-implicit-templates
-fno-threadsafe-statics
-fno-use-cxa-atexit
...
@@ -19,26 +22,30 @@ CFLAGS=-Wall -Wextra -Wpedantic -std=gnu11 -nostartfiles -fno-PIC $(COPTFLAGS)
...
@@ -19,26 +22,30 @@ CFLAGS=-Wall -Wextra -Wpedantic -std=gnu11 -nostartfiles -fno-PIC $(COPTFLAGS)
CXXFLAGS
=
-Wall
-Wextra
-Wpedantic
-std
=
c++11
$(CXXOPTFLAGS)
-nostartfiles
-fno-PIC
CXXFLAGS
=
-Wall
-Wextra
-Wpedantic
-std
=
c++11
$(CXXOPTFLAGS)
-nostartfiles
-fno-PIC
ASFLAGS
=
-I
$(SRCDIR)
/
ASFLAGS
=
-I
$(SRCDIR)
/
LDFLAGS_
:=
ifeq
($(BITS),32)
ifeq
($(BITS),32)
LDFLAGS
=
-m
elf_i386
LDFLAGS
+=
-m32
ASFLAGS
+=
-f
elf32
ASFLAGS
+=
-f
elf32
LDFLAGS_
:=
-m32
else
else
LDFLAGS
=
-m
elf_x86_
64
LDFLAGS
+=
-m
64
ASFLAGS
+=
-f
elf64
ASFLAGS
+=
-f
elf64
LDFLAGS_
:=
-m64
endif
endif
LDFLAGS_
=
$(LDFLAGS)
-T
$(LDDIR)
/link.ld
--oformat
=
binary
LDFLAGS
+=
-nostartfiles
-nostdlib
LDFLAGS_
:=
$(LDFLAGS_)
-T
$(LDDIR)
/link.ld
-Wl
,--oformat
=
binary
$(LDFLAGS)
CFLAGS
+=
-m
$(BITS)
$(
shell
pkg-config
--cflags
sdl2
)
CFLAGS
+=
-m
$(BITS)
$(
shell
pkg-config
--cflags
sdl2
)
CXXFLAGS
+=
-m
$(BITS)
$(
shell
pkg-config
--cflags
sdl2
)
CXXFLAGS
+=
-m
$(BITS)
$(
shell
pkg-config
--cflags
sdl2
)
LIBS
=
-lc
LIBS
=
-lc
ASFLAGS
+=
-DUSE_INTERP
-DALIGN_STACK
-DUSE_DT_DEBUG
-DNO_START_ARG
ASFLAGS
+=
-DUSE_INTERP
-DALIGN_STACK
#
-DUSE_DT_DEBUG
#
-DNO_START_ARG
NASM
?=
nasm
NASM
?=
nasm
PYTHON3
?=
python3
PYTHON3
?=
python3
all
:
$(BINDIR)/hello-crt $(BINDIR)/sdl-crt $(BINDIR)/flag $(BINDIR)/hello-_start
all
:
$(BINDIR)/hello-crt $(BINDIR)/sdl-crt $(BINDIR)/flag
-crt
$(BINDIR)/hello-_start
LIBS
+=
$(
filter-out
-pthread
,
$(
shell
pkg-config
--libs
sdl2
))
-lX11
#-lGL
LIBS
+=
$(
filter-out
-pthread
,
$(
shell
pkg-config
--libs
sdl2
))
-lX11
#-lGL
...
@@ -50,13 +57,18 @@ clean:
...
@@ -50,13 +57,18 @@ clean:
.SECONDARY
:
.SECONDARY
:
$(OBJDIR)/%.lto.o
:
$(SRCDIR)/%.c $(OBJDIR)/
$(CC)
-flto
$(CFLAGS)
-c
"
$<
"
-o
"
$@
"
$(OBJDIR)/%.lto.o
:
$(TESTDIR)/%.c $(OBJDIR)/
$(CC)
-flto
$(CFLAGS)
-c
"
$<
"
-o
"
$@
"
$(OBJDIR)/%.o
:
$(SRCDIR)/%.c $(OBJDIR)/
$(OBJDIR)/%.o
:
$(SRCDIR)/%.c $(OBJDIR)/
$(CC)
$(CFLAGS)
-c
"
$<
"
-o
"
$@
"
$(CC)
$(CFLAGS)
-c
"
$<
"
-o
"
$@
"
$(OBJDIR)/%.o
:
$(TESTDIR)/%.c $(OBJDIR)/
$(OBJDIR)/%.o
:
$(TESTDIR)/%.c $(OBJDIR)/
$(CC)
$(CFLAGS)
-c
"
$<
"
-o
"
$@
"
$(CC)
$(CFLAGS)
-c
"
$<
"
-o
"
$@
"
$(OBJDIR)/%.start.o
:
$(OBJDIR)/%.o $(OBJDIR)/crt1.o
$(OBJDIR)/%.start.o
:
$(OBJDIR)/%.
lto.
o $(OBJDIR)/crt1.
lto.
o
$(
LD
)
$(LDFLAGS)
-r
-o
"
$@
"
$^
$(
CC
)
$(LDFLAGS)
-r
-o
"
$@
"
$^
$(OBJDIR)/symbols.%.asm
:
$(OBJDIR)/%.o
$(OBJDIR)/symbols.%.asm
:
$(OBJDIR)/%.o
$(PYTHON3)
./smol.py
$(SMOLFLAGS)
$(LIBS)
"
$<
"
"
$@
"
$(PYTHON3)
./smol.py
$(SMOLFLAGS)
$(LIBS)
"
$<
"
"
$@
"
...
@@ -70,10 +82,10 @@ $(OBJDIR)/stub.%.start.o: $(OBJDIR)/symbols.%.start.asm $(SRCDIR)/header32.asm \
...
@@ -70,10 +82,10 @@ $(OBJDIR)/stub.%.start.o: $(OBJDIR)/symbols.%.start.asm $(SRCDIR)/header32.asm \
$(NASM)
$(ASFLAGS)
$<
-o
$@
$(NASM)
$(ASFLAGS)
$<
-o
$@
$(BINDIR)/%
:
$(OBJDIR)/%.o $(OBJDIR)/stub.%.o $(BINDIR)/
$(BINDIR)/%
:
$(OBJDIR)/%.o $(OBJDIR)/stub.%.o $(BINDIR)/
$(
LD)
-Map
=
$(BINDIR)
/
$*
.map
$(LDFLAGS_)
$(OBJDIR)
/
$*
.o
$(OBJDIR)
/stub.
$*
.o
-o
"
$@
"
$(
CC)
-Wl
,
-Map
=
$(BINDIR)
/
$*
.map
$(LDFLAGS_)
$(OBJDIR)
/
$*
.o
$(OBJDIR)
/stub.
$*
.o
-o
"
$@
"
$(BINDIR)/%-crt
:
$(OBJDIR)/%.start.o $(OBJDIR)/stub.%.start.o $(BINDIR)/
$(BINDIR)/%-crt
:
$(OBJDIR)/%.start.o $(OBJDIR)/stub.%.start.o $(BINDIR)/
$(
LD)
-Map
=
$(BINDIR)
/
$*
-crt
.map
$(LDFLAGS_)
$(OBJDIR)
/
$*
.start.o
$(OBJDIR)
/stub.
$*
.start.o
-o
"
$@
"
$(
CC)
-Wl
,
-Map
=
$(BINDIR)
/
$*
-crt
.map
$(LDFLAGS_)
$(OBJDIR)
/
$*
.start.o
$(OBJDIR)
/stub.
$*
.start.o
-o
"
$@
"
.PHONY
:
all clean
.PHONY
:
all clean
src/crt1.c
View file @
434630e6
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include <stddef.h>
#include <stddef.h>
extern
int
main
(
int
argc
,
char
*
argv
[]);
extern
int
main
(
int
argc
,
char
*
argv
[]);
extern
int
__libc_start_main
(
int
(
*
main
)(
int
,
char
**
),
extern
int
__libc_start_main
(
int
(
*
main
)(
int
,
char
**
),
int
argc
,
char
**
argv
,
int
argc
,
char
**
argv
,
void
(
*
init
)(
void
),
void
(
*
fini
)(
void
),
void
(
*
init
)(
void
),
void
(
*
fini
)(
void
),
...
@@ -9,14 +10,30 @@ extern int __libc_start_main(int (*main)(int, char**),
...
@@ -9,14 +10,30 @@ extern int __libc_start_main(int (*main)(int, char**),
void
*
stack
)
__attribute__
((
__noreturn__
));
void
*
stack
)
__attribute__
((
__noreturn__
));
__attribute__
((
__externally_visible__
,
__section__
(
".text.startup._start"
),
__attribute__
((
__externally_visible__
,
__section__
(
".text.startup._start"
),
__noreturn__
))
__noreturn__
,
__used__
#ifdef __x86_64__
,
__naked__
#endif
))
int
_start
(
void
*
stack
)
{
int
_start
(
void
*
stack
)
{
// TODO: _dl_fini etc.
// TODO: _dl_fini etc.
int
argc
=*
(
size_t
*
)
stack
;
int
argc
=*
(
size_t
*
)
stack
;
char
**
argv
=
(
void
*
)(
&
((
size_t
*
)
stack
)[
1
]);
char
**
argv
=
(
void
*
)(
&
((
size_t
*
)
stack
)[
1
]);
// TODO: fix this. it borks with -fno-plt
// avoid problems when -fno-plt is enabled
#ifdef __x86_64__
asm
volatile
(
"xor %%ecx, %%ecx
\n
"
"push %%rcx
\n
"
"push %%rcx
\n
"
"pop %%r8
\n
"
"pop %%r9
\n
"
"call *__libc_start_main@GOTPCREL(%%rip)
\n
"
:
:
"S"
(
argc
),
"D"
(
main
),
"d"
(
argv
)
:
);
#else
__libc_start_main
(
main
,
argc
,
argv
,
NULL
,
NULL
,
NULL
,
(
void
*
)
stack
);
__libc_start_main
(
main
,
argc
,
argv
,
NULL
,
NULL
,
NULL
,
(
void
*
)
stack
);
#endif
__builtin_unreachable
();
__builtin_unreachable
();
}
}
...
...
src/loader64.asm
View file @
434630e6
...
@@ -142,7 +142,8 @@ repne scasd ; technically, scasq should be used, but ehhhh
...
@@ -142,7 +142,8 @@ repne scasd ; technically, scasq should be used, but ehhhh
mov
rdi
,
rsp
mov
rdi
,
rsp
%endif
%endif
%ifdef ALIGN_STACK
%ifdef ALIGN_STACK
push
rax
; apparently not needed?
; push rax
%endif
%endif
%ifdef USE_DL_FINI
%ifdef USE_DL_FINI
xchg
rsi
,
r13
; _dl_fini
xchg
rsi
,
r13
; _dl_fini
...
...
test/flag.c
View file @
434630e6
...
@@ -10,9 +10,9 @@
...
@@ -10,9 +10,9 @@
#define COLOR(r, g, b) ((r << 16) + (g << 8) + b)
#define COLOR(r, g, b) ((r << 16) + (g << 8) + b)
__attribute__
((
__used__
,
__externally_visible__
))
/*
__attribute__((__used__,__externally_visible__))
void
_start
()
{
void _start() {
*/
/*
int main() {
*/
int
main
()
{
#ifdef MAKE_ESC_WORK
#ifdef MAKE_ESC_WORK
Atom
wmDeleteMessage
;
Atom
wmDeleteMessage
;
#endif
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment