Skip to content

Commit

Permalink
Added contained symbols example
Browse files Browse the repository at this point in the history
* added example that produces symbols which are contained fully within
  another
* updated the README with this example
  • Loading branch information
fzakaria committed Sep 14, 2023
1 parent e0959d0 commit 9961a7c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ sqlelf.egg-info/
.vscode/
dist/
result
examples/shadowed-symbols/exe
examples/**/exe
examples/**/*.so
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,32 @@ HAVING count(*) >= 2;"
```
</details>

<details>
<summary> List contained symbols, i.e. a symbol fully within the bounds of another</summary>

```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 │
└──────────────────────────────────┴───────────────────┴───────────────────┘
```

</details>

## Development

You must have [Nix](https://nixos.org) installed for development.
Expand Down
15 changes: 15 additions & 0 deletions examples/nested-symbols/Makefile
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions examples/nested-symbols/nested.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>

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;
}

0 comments on commit 9961a7c

Please sign in to comment.