Commit 9f57498e authored by PoroCYon's avatar PoroCYon Committed by PoroCYon
Browse files

fix smol wrt new glibc version, make mksyms much faster

parent d87b11a6
......@@ -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 $@
; 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
......
......@@ -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
......
; 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 0x178
%define LM_GNU_BUCKETS_OFFSET 0x188
%define LM_GNU_CHAIN_ZERO_OFFSET 0x18C
%define LM_NBUCKETS_OFFSET 0x17c
%define LM_GNU_BUCKETS_OFFSET 0x18c
%define LM_GNU_CHAIN_ZERO_OFFSET 0x190
%define DT_VALUE_OFFSET 0x4
%define DYN_PTR_OFFSET 0x4
......@@ -128,3 +129,4 @@ _start:
call main
int3
#!/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'\x7FELF'
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 libraries):
if symbol in sym.split(',') and any(soname.startswith('lib'+l) for l in libnames):
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'], libraries, symbol)
library = find_symbol(libs, libnames, symbol)
if not library:
sys.stderr.write('could not find symbol: {}\n'.format(symbol))
sys.exit(1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment