-
Notifications
You must be signed in to change notification settings - Fork 17
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
12 changed files
with
149 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,26 @@ | ||
PROGS = ab a.o b.o ManualNameMangling SimpleSection.o SpecialSymbol \ | ||
target TinyHelloWorld SectionMapping.elf | ||
|
||
all: $(PROGS) | ||
|
||
clean: | ||
rm -f $(PROGS) | ||
|
||
ab: a.o b.o | ||
$(LD) a.o b.o -e main -o ab | ||
|
||
ManualNameMangling: ManualNameMangling.cc | ||
$(CXX) ManualNameMangling.cc -o ManualNameMangling | ||
|
||
SpecialSymbol: SpecialSymbol.c | ||
$(CC) $< -o $@ | ||
|
||
target: target.c | ||
$(CC) -o $@ $< -lbfd | ||
|
||
TinyHelloWorld: TinyHelloWorld.c TinyHelloWorld.lds | ||
$(CC) -c -fno-builtin TinyHelloWorld.c | ||
$(LD) -static -T TinyHelloWorld.lds -o $@ TinyHelloWorld.o | ||
|
||
SectionMapping.elf: SectionMapping.c | ||
$(CC) -static $< -o $@ |
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,12 @@ | ||
#include <stdio.h> | ||
|
||
namespace myname { | ||
int var = 42; | ||
} | ||
|
||
extern "C" int _ZN6myname3varE; | ||
|
||
int main() { | ||
printf("%d\n", _ZN6myname3varE); | ||
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,7 @@ | ||
#include <stdlib.h> | ||
|
||
int main() { | ||
while(1) | ||
sleep(1000); | ||
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,20 @@ | ||
int printf(const char *format, ...); | ||
|
||
int global_init_var = 84; | ||
int global_uninit_var; | ||
|
||
void func1(int i) { | ||
printf("%d\n", i); | ||
} | ||
|
||
int main(void) { | ||
static int static_var = 85; | ||
static int staic_var2; | ||
|
||
int a = 1; | ||
int b; | ||
|
||
func1(static_var + staic_var2 + a + b); | ||
|
||
return a; | ||
} |
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,14 @@ | ||
#include <stdio.h> | ||
|
||
extern char *__executable_start; | ||
extern char *etext, *_etext, *__etext; | ||
extern char *edata, *_edata; | ||
extern char *end, *_end; | ||
|
||
int main() { | ||
printf("Executable start %X\n", __executable_start); | ||
printf("Text end %X %X %X\n", etext, _etext, __etext); | ||
printf("Data end %X %X\n", edata, _edata); | ||
printf("Executable end %X %X\n", end, _end); | ||
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,21 @@ | ||
char *str = "Hello World!\n"; | ||
|
||
void print() { | ||
asm("movl $13, %%edx\n\t" // length | ||
"movl %%eax, %%ecx\n\t" // str | ||
"movl $0, %%ebx\n\t" // STDOUT | ||
"movl $4, %%eax\n\t" // write | ||
"int $0x80\n\t" | ||
:: "r" (str) : "edx", "ecx", "ebx"); | ||
} | ||
|
||
void exit() { | ||
asm("movl $42, %ebx\n\t" // exit code | ||
"movl $1, %eax\n\t" // exit | ||
"int $0x80\n\t"); | ||
} | ||
|
||
void nomain() { | ||
print(); | ||
exit(); | ||
} |
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,8 @@ | ||
ENTRY(nomain) | ||
|
||
SECTIONS | ||
{ | ||
. = 0x00400000 + SIZEOF_HEADERS; | ||
tinytext : { *(.text) *(.data) *(.rodata) } | ||
/DISCARD/ : { *(.comment) } | ||
} |
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,6 @@ | ||
extern int shared; | ||
|
||
int main() { | ||
int a = 100; | ||
swap(&a, &shared); | ||
} |
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,5 @@ | ||
int shared = 1; | ||
|
||
void swap(int *a, int *b) { | ||
*a ^= *b ^= *a ^= *b; | ||
} |
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,7 @@ | ||
int weak; | ||
int strong = 1; | ||
__attribute__((weak)) weak2 = 2; | ||
|
||
int main() { | ||
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,9 @@ | ||
#include <stdio.h> | ||
#include <bfd.h> | ||
|
||
int main() { | ||
const char **t = bfd_target_list(); | ||
while(*t) { | ||
puts(*t++); | ||
} | ||
} |
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,14 @@ | ||
#include <stdio.h> | ||
#include <pthread.h> | ||
|
||
int pthread_create(pthread_t *, const pthread_attr_t *, | ||
void *(*) (void *), void *) __attribute__ ((weak)); | ||
|
||
int main() { | ||
if(pthread_create) { | ||
puts("This is multi-threaded version."); | ||
} else { | ||
puts("This is single-threaded version."); | ||
} | ||
return 0; | ||
} |