Register - Login
Views: 99796249
Main - Memberlist - Active users - Calendar - Wiki - IRC Chat - Online users
Ranks - Rules/FAQ - Stats - Latest Posts - Color Chart - Smilies
05-03-22 05:37:51 AM
Jul - Computers and Technology - Linking raw file with gcc? New poll - New thread - New reply
Next newer thread | Next older thread
shyguyhex

Level: 16


Posts: 30/45
EXP: 16647
For next: 3609

Since: 01-04-14


Since last post: 6.9 years
Last activity: 6.4 years

Posted on 09-21-14 03:21:02 PM (last edited by shyguyhex at 09-21-14 03:51:51 PM) Link | Quote
So I have two tables of structs that I would like to add into my project at link time.

I made the object files using objcopy:

objcopy -I binary -O elf32-i386 -B i386 asm_functions.bin objects\asm_functions.bin.o

objcopy -I binary -O elf32-i386 -B i386 asm_operations.bin objects\asm_operations.bin.o


Then I linked them with gcc:

gcc -w res\b64.res objects\asm_functions.bin.o objects\asm_operations.bin.o b64si.c -o b64si.exe



These are the symbols I'm suppose to use, but gcc tells me that they are undefined when I try to use them:

_binary_asm_operations_bin_start

_binary_asm_functions_bin_start


extern const int _binary_asm_operations_bin_start[];

extern const int _binary_asm_functions_bin_start[];


I know that these are the right symbols because I checked the object files with a hex editor; I checked the final exe as well, and my table and the symbols were in there. So I'm confused as to why the symbols aren't defined. Any help would be appreciated.

(win7 32bit)

____________________

Web R4300i Assembler
Guide to SM64 Behavior Scripts
GS Code Formatter for Nemu's silly Cheats.ini
shyguyhex

Level: 16


Posts: 31/45
EXP: 16647
For next: 3609

Since: 01-04-14


Since last post: 6.9 years
Last activity: 6.4 years

Posted on 09-21-14 07:17:58 PM Link | Quote
Managed to find a solution that works.


extern int testdata[] asm("_binary_asm_operations_bin_start")



____________________

Web R4300i Assembler
Guide to SM64 Behavior Scripts
GS Code Formatter for Nemu's silly Cheats.ini
andlabs
Member
Level: 38


Posts: 214/309
EXP: 361453
For next: 8994

Since: 03-19-10

From: United States

Since last post: 1.1 years
Last activity: 138 days

Posted on 09-21-14 07:26:39 PM Link | Quote
Late but what happens if you get rid of the leading underscore?
Joe
Common spammer
🍬
Level: 111


Posts: 3157/3392
EXP: 14501080
For next: 367280

Since: 08-02-07

From: Pororoca

Since last post: 12 days
Last activity: 7 hours

Posted on 09-21-14 10:08:41 PM Link | Quote
Originally posted by andlabs
leading underscore

This is the problem. The MinGW version of gcc adds an underscore to all symbols when it generates assembly code.

The correct fix is to remove the underscores in the C code.

____________________
ふにゃあ。
shyguyhex

Level: 16


Posts: 32/45
EXP: 16647
For next: 3609

Since: 01-04-14


Since last post: 6.9 years
Last activity: 6.4 years

Posted on 09-22-14 01:13:57 AM (last edited by shyguyhex at 09-22-14 01:24:42 AM) Link | Quote
Thanks guys, that works. Now my code is less funky looking .

I find it rather confusing that all the examples I can find about binary linking have people using the leading underscores in their code though


http://balau82.wordpress.com/2012/02/19/linking-a-binary-blob-with-gcc/
http://bytbox.net/blog/2012/11/linking-raw-data.html

____________________

Web R4300i Assembler
Guide to SM64 Behavior Scripts
GS Code Formatter for Nemu's silly Cheats.ini
Joe
Common spammer
🍬
Level: 111


Posts: 3159/3392
EXP: 14501080
For next: 367280

Since: 08-02-07

From: Pororoca

Since last post: 12 days
Last activity: 7 hours

Posted on 09-22-14 11:45:26 AM Link | Quote
Those examples are all for the Linux (System V) ABI. The 32-bit Windows ABI has specific name mangling requirements, and MinGW follows them in order to maintain compatibility across different compilers and object files.

The 64-bit Windows ABI is much more similar to the System V ABI, so for something simple like this you could probably use the same code on both.

(Technically, there are multiple System V ABIs, one for each CPU architecture. As far as I know, they all have the same name mangling semantics, so I'm ignoring the differences here.)

____________________
ふにゃあ。
Next newer thread | Next older thread
Jul - Computers and Technology - Linking raw file with gcc? New poll - New thread - New reply


Rusted Logic

Acmlmboard - commit 47be4dc [2021-08-23]
©2000-2022 Acmlm, Xkeeper, Kaito Sinclaire, et al.

29 database queries, 1 query cache hits.
Query execution time: 0.080674 seconds
Script execution time: 0.012577 seconds
Total render time: 0.093251 seconds