-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright 2025 Yury Gribov | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Use of this source code is governed by MIT license that can be | ||
* found in the LICENSE.txt file. | ||
*/ | ||
|
||
#include "interposed.h" | ||
|
||
__attribute__((visibility("default"))) | ||
void foo() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright 2025 Yury Gribov | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Use of this source code is governed by MIT license that can be | ||
* found in the LICENSE.txt file. | ||
*/ | ||
|
||
#ifndef INTERPOSED_H | ||
#define INTERPOSED_H | ||
|
||
extern void foo(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2025 Yury Gribov | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Use of this source code is governed by MIT license that can be | ||
* found in the LICENSE.txt file. | ||
*/ | ||
|
||
#include "interposed.h" | ||
|
||
#define NITER 1000000000L | ||
|
||
int main() { | ||
for (long i = 0; i < NITER; ++i) | ||
#ifdef BASELINE | ||
asm volatile(""); | ||
#else | ||
foo(); | ||
#endif | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/sh | ||
|
||
# Copyright 2025 Yury Gribov | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# Use of this source code is governed by MIT license that can be | ||
# found in the LICENSE.txt file. | ||
|
||
# This is a simple benchmark of Implib's overhead. | ||
# | ||
# On my machine results are very close, Implib being 0.5-1% slower. | ||
|
||
set -eu | ||
|
||
cd $(dirname $0) | ||
|
||
if test -n "${1:-}"; then | ||
ARCH="$1" | ||
fi | ||
|
||
. ../common.sh | ||
|
||
CFLAGS="-g -O2 $CFLAGS" | ||
N=10 | ||
|
||
# Need sudo for nice... | ||
RUN='nice -n -20 taskset 1' | ||
|
||
$CC $CFLAGS -shared -fPIC interposed.c -o libinterposed.so | ||
${PYTHON:-} ../../implib-gen.py -q --target $TARGET libinterposed.so | ||
|
||
export LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-} | ||
|
||
# Baseline | ||
|
||
$CC $CFLAGS -DBASELINE main.c | ||
|
||
echo "Baseline:" | ||
$RUN time ./a.out | ||
|
||
# Normal | ||
|
||
$CC $CFLAGS main.c -L. -linterposed $LIBS | ||
|
||
echo "Normal:" | ||
$RUN time ./a.out | ||
|
||
# Implib | ||
|
||
$CC $CFLAGS main.c libinterposed.so.tramp.S libinterposed.so.init.c $LIBS | ||
|
||
echo "Implib:" | ||
$RUN time ./a.out | ||
|
||
# Implib (IMPLIB_EXPORT_SHIMS) | ||
|
||
$CC $CFLAGS -DIMPLIB_EXPORT_SHIMS -rdynamic main.c libinterposed.so.tramp.S libinterposed.so.init.c $LIBS | ||
|
||
echo "Implib (IMPLIB_EXPORT_SHIMS):" | ||
$RUN time ./a.out |