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
9f57498e
Commit
9f57498e
authored
Jan 25, 2019
by
PoroCYon
Committed by
PoroCYon
Feb 27, 2019
Browse files
fix smol wrt new glibc version, make mksyms much faster
parent
d87b11a6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
9f57498e
...
...
@@ -4,7 +4,7 @@ BINDIR = bin
SRCDIR
=
src
DATADIR
=
data
COPTFLAGS
=
-Os
-fvisibility
=
hidden
-mpreferred-stack-boundary
=
2
-fwhole-program
\
COPTFLAGS
=
-Os
-fvisibility
=
hidden
-mpreferred-stack-boundary
=
3
-fwhole-program
\
-ffast-math
-funsafe-math-optimizations
-fno-stack-protector
-fomit-frame-pointer
\
-fno-exceptions
-fno-unwind-tables
-fno-asynchronous-unwind-tables
CXXOPTFLAGS
=
$(COPTFLAGS)
\
...
...
@@ -14,7 +14,7 @@ CXXOPTFLAGS=$(COPTFLAGS) \
ASFLAGS
=
-f
elf
-I
$(LDRDIR)
/
CFLAGS
=
-Wall
-Wextra
-Wpedantic
-std
=
c99
$(COPTFLAGS)
-nostartfiles
-fno-PIC
CXXFLAGS
=
-Wall
-Wextra
-Wpedantic
-std
=
c++11
$(CXXOPTFLAGS)
-nostartfiles
-fno-PIC
LIBS
=
-lGL
-ldl
-lc
LIBS
=
-lc
LDFLAGS
=
--oformat
=
binary
-T
ldr/link.ld
...
...
@@ -29,7 +29,7 @@ clean:
.SECONDARY
:
$(OBJDIR)/%.o
:
$(SRCDIR)/%.c
$(CC)
$(CFLAGS)
-c
$^
-o
$@
$(CC)
-m32
$(CFLAGS)
-c
$^
-o
$@
$(OBJDIR)/%.o.syms
:
$(OBJDIR)/%.o
readelf
-s
$^
|
grep
UND |
sed
1d |
awk
'{ print $$8 }'
>
$@
...
...
@@ -41,4 +41,4 @@ $(OBJDIR)/header.%.o: $(OBJDIR)/symbols.%.s $(LDRDIR)/header.s $(LDRDIR)/loader.
nasm
$(ASFLAGS)
$<
-o
$@
$(BINDIR)/%
:
$(OBJDIR)/%.o $(OBJDIR)/header.%.o
$(LD)
$(LDFLAGS)
$^
-o
$@
$(LD)
-m
elf_i386
$(LDFLAGS)
$^
-o
$@
ldr/header.s
View file @
9f57498e
; vim: set ft=nasm:
%
define
ORIGIN
0x400000
extern
_size
...
...
@@ -31,6 +32,7 @@ header:
; e_phentsize
dw
(
.
segments
.
load
-
.
segments
.
dynamic
)
.
segments
:
; TODO: .segments.interp
.
segments
.
dynamic
:
; {e_phnum: 2, e_shentsize: 0}, p_type: 2 = PT_DYNAMIC
dd
2
...
...
ldr/link.ld
View file @
9f57498e
...
...
@@ -10,7 +10,7 @@ SECTIONS {
}
.data : {
*(.data .data.* .
bss .bss.* .
tdata .tdata.* .tbss .tbss.*)
*(.data .data.* .tdata .tdata
.* .bss .bss
.* .tbss .tbss.*)
}
.dynamic : { *(.dynamic) } :all :dyn
...
...
ldr/loader.s
View file @
9f57498e
; vim: set ft=nasm ts=8:
[
section
.
text
]
%
define
LM_NAME_OFFSET
0x4
%
define
LM_NEXT_OFFSET
0xC
%
define
LM_ADDR_OFFSET
0
%
define
LM_INFO_OFFSET
0x20
%
define
LM_NBUCKETS_OFFSET
0x17
8
%
define
LM_GNU_BUCKETS_OFFSET
0x18
8
%
define
LM_GNU_CHAIN_ZERO_OFFSET
0x1
8C
%
define
LM_NBUCKETS_OFFSET
0x17
c
%
define
LM_GNU_BUCKETS_OFFSET
0x18
c
%
define
LM_GNU_CHAIN_ZERO_OFFSET
0x1
90
%
define
DT_VALUE_OFFSET
0x4
%
define
DYN_PTR_OFFSET
0x4
...
...
@@ -128,3 +129,4 @@ _start:
call
main
int3
ldr/mksyms
View file @
9f57498e
#!/usr/bin/env python3
import
glob
import
sys
import
os.path
import
subprocess
...
...
@@ -40,19 +42,39 @@ def output_x86(libraries):
def
get_cc_paths
():
output
=
subprocess
.
check_output
([
'cc'
,
'-print-search-dirs'
],
stderr
=
subprocess
.
DEVNULL
)
output
=
subprocess
.
check_output
([
'cc'
,
'-print-search-dirs'
],
stderr
=
subprocess
.
DEVNULL
)
paths
=
{}
for
entry
in
output
.
decode
(
'utf-8'
).
splitlines
():
category
,
path
=
entry
.
split
(
': '
,
1
)
path
=
path
.
lstrip
(
'='
)
paths
[
category
]
=
list
(
set
(
os
.
path
.
realpath
(
p
)
for
p
in
path
.
split
(
':'
)
if
os
.
path
.
isdir
(
p
)))
paths
[
category
]
=
list
(
set
(
os
.
path
.
realpath
(
p
)
\
for
p
in
path
.
split
(
':'
)
if
os
.
path
.
isdir
(
p
)))
return
paths
def
find_symbol
(
paths
,
libraries
,
symbol
):
output
=
subprocess
.
check_output
([
'scanelf'
,
'-B'
,
'-F'
'%s %S'
,
'-s'
,
'+{}'
.
format
(
symbol
)]
+
paths
,
stderr
=
subprocess
.
DEVNULL
)
def
is_valid_elf
(
f
):
with
open
(
f
,
'rb'
)
as
ff
:
return
ff
.
read
(
4
)
==
b
'
\x7F
ELF'
def
find_lib
(
spaths
,
wanted
):
for
p
in
spaths
:
for
f
in
glob
.
glob
(
glob
.
escape
(
p
)
+
'/lib'
+
wanted
+
'.so*'
):
if
os
.
path
.
isfile
(
f
)
and
is_valid_elf
(
f
):
return
f
for
f
in
glob
.
glob
(
glob
.
escape
(
p
)
+
'/'
+
wanted
+
'.so*'
):
if
os
.
path
.
isfile
(
f
)
and
is_valid_elf
(
f
):
return
f
#for f in glob.glob(glob.escape(p) + '/lib' + wanted + '.a' ): return f
#for f in glob.glob(glob.escape(p) + '/' + wanted + '.a' ): return f
sys
.
stderr
.
write
(
"E: couldn't find library '"
+
wanted
+
"'."
)
sys
.
exit
(
1
)
def
find_libs
(
spaths
,
wanted
):
return
map
(
lambda
l
:
find_lib
(
spaths
,
l
),
wanted
)
def
find_symbol
(
libraries
,
libnames
,
symbol
):
output
=
subprocess
.
check_output
([
'scanelf'
,
'-B'
,
'-F'
'%s %S'
,
'-s'
,
\
'+{}'
.
format
(
symbol
)]
+
libraries
,
stderr
=
subprocess
.
DEVNULL
)
for
entry
in
output
.
decode
(
'utf-8'
).
splitlines
():
sym
,
soname
,
path
=
entry
.
split
(
' '
,
2
)
if
symbol
in
sym
.
split
(
','
)
and
any
(
soname
.
startswith
(
l
)
for
l
in
lib
rari
es
):
if
symbol
in
sym
.
split
(
','
)
and
any
(
soname
.
startswith
(
'lib'
+
l
)
for
l
in
lib
nam
es
):
return
soname
def
main
():
...
...
@@ -63,11 +85,14 @@ def main():
args
=
parser
.
parse_args
()
paths
=
get_cc_paths
()
libraries
=
paths
[
'libraries'
]
libnames
=
args
.
library
libs
=
list
(
find_libs
(
libraries
,
libnames
))
sys
.
stderr
.
write
(
'libs='
+
str
(
libs
)
+
'
\n
'
)
symbols
=
{}
libraries
=
[
'lib{}'
.
format
(
l
)
for
l
in
args
.
library
or
[]]
for
symbol
in
args
.
symbols
:
library
=
find_symbol
(
paths
[
'libraries'
]
,
lib
rari
es
,
symbol
)
library
=
find_symbol
(
libs
,
lib
nam
es
,
symbol
)
if
not
library
:
sys
.
stderr
.
write
(
'could not find symbol: {}
\n
'
.
format
(
symbol
))
sys
.
exit
(
1
)
...
...
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