From 9961a7c91a58455af1f972e5412ee4f6751ed3d3 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Thu, 14 Sep 2023 22:15:55 +0000 Subject: [PATCH] Added contained symbols example * added example that produces symbols which are contained fully within another * updated the README with this example --- .gitignore | 2 +- README.md | 26 ++++++++++++++++++++++++++ examples/nested-symbols/Makefile | 15 +++++++++++++++ examples/nested-symbols/nested.c | 17 +++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 examples/nested-symbols/Makefile create mode 100644 examples/nested-symbols/nested.c diff --git a/.gitignore b/.gitignore index a05c094..26cf45e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,5 @@ sqlelf.egg-info/ .vscode/ dist/ result -examples/shadowed-symbols/exe +examples/**/exe examples/**/*.so diff --git a/README.md b/README.md index 4fd1ebc..937dfee 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,32 @@ HAVING count(*) >= 2;" ``` +
+ List contained symbols, i.e. a symbol fully within the bounds of another + +```console +sqlelf ./examples/nested-symbols/exe --sql " +SELECT outer_symbol.path, + outer_symbol.name AS outer_symbol_name, + inner_symbol.name AS inner_symbol_name +FROM + elf_symbols AS outer_symbol, + elf_symbols AS inner_symbol +WHERE + inner_symbol.section = '.text' AND + outer_symbol.section = '.text' AND + inner_symbol.path = outer_symbol.path AND + inner_symbol.value > outer_symbol.value AND + (inner_symbol.value + inner_symbol.size) < (outer_symbol.value + outer_symbol.size) AND + inner_symbol.name != outer_symbol.name LIMIT 5;" +┌──────────────────────────────────┬───────────────────┬───────────────────┐ +│ path │ outer_symbol_name │ inner_symbol_name │ +│ ./examples/nested-symbols/nested │ outer_function │ inner_symbol │ +└──────────────────────────────────┴───────────────────┴───────────────────┘ +``` + +
+ ## Development You must have [Nix](https://nixos.org) installed for development. diff --git a/examples/nested-symbols/Makefile b/examples/nested-symbols/Makefile new file mode 100644 index 0000000..7023539 --- /dev/null +++ b/examples/nested-symbols/Makefile @@ -0,0 +1,15 @@ +# Variables +CC = gcc +CFLAGS = -Wall -O2 +TARGET = exe +SRC = nested.c + +# Default rule +all: $(TARGET) + +$(TARGET): $(SRC) + $(CC) $(CFLAGS) -o $@ $< + +.PHONY: clean +clean: + rm -f $(TARGET) \ No newline at end of file diff --git a/examples/nested-symbols/nested.c b/examples/nested-symbols/nested.c new file mode 100644 index 0000000..7865642 --- /dev/null +++ b/examples/nested-symbols/nested.c @@ -0,0 +1,17 @@ +#include + +void outer_function() { + printf("This is the beginning of the outer function.\n"); + + asm volatile( + ".global inner_symbol\n" + "inner_symbol:\n" + "nop\n"); + + printf("This is the end of the outer function.\n"); +} + +int main() { + outer_function(); + return 0; +}