Linker script rodata

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Linker script rodata

Post by piranha »

Does anybody have a sample linker script that keeps rodata?
I need to link a simple C file against my library and have the out format be binary.

Thanks, JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Try linker.ld from the Bare Bones tutorial.
Every good solution is obvious once you've found it.
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

Well, my kernel simply loads the binary into memory and jumps to it.
With this code and the Bare Bones script:

Code: Select all

char b[16];
	b[0] = 'S';
	b[1] = 'y';
	b[2] = 'n';
	b[3] = 'c';
	b[4] = 'i';
	b[5] = 'n';
	b[6] = 'g';
	b[7] = '\n';
	b[8] = '\0';
	kputs(b);
	kputs("fine");
I get:

Code: Select all

Syncing
And thats it.
It should say 'fine'....Do you need any more info?

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
ucosty
Member
Member
Posts: 271
Joined: Tue Aug 08, 2006 7:43 am
Location: Sydney, Australia

Post by ucosty »

Objdump your executable and make sure the data is really in there. Dissassemble the relevant source and make sure it is pointing to your rodata section.
The cake is a lie | rackbits.com
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

Objdump output (when I compile it to an elf):

Code: Select all

Disassembly of section .rodata:

00101000 <_ebss-0x18>:
  101000:       66 69 6e 65 00 2e       imul   $0x2e00,0x65(%esi),%bp
  101006:       2e 2e 00 77 6f          add    %dh,%cs:0x6f(%edi)
  10100b:       72 6b                   jb     101078 <_ebss+0x60>
  10100d:       3f                      aas
  10100e:       00 57 61                add    %dl,0x61(%edi)
  101011:       69                      .byte 0x69
  101012:       74 2e                   je     101042 <_ebss+0x2a>
  101014:       2e                      cs
  101015:       2e                      cs
        ...
So it looks like it's there...Edit: Is the actual data there?
Heres a newer one:

Code: Select all

	char b[16];
	b[0] = 'S';
	b[1] = 'y';
	b[2] = 'n';
	b[3] = 'c';
	b[4] = 'i';
	b[5] = 'n';
	b[6] = 'g';
	b[7] = '\n';
	b[8] = '\0';
	kputs(b);
	char c[16] = "Hello!\0";
	kputs(c);
Goes to

Code: Select all

Disassembly of section .rodata:

08048103 <.rodata>:
 8048103:       48                      dec    %eax
 8048104:       65                      gs
 8048105:       6c                      insb   (%dx),%es:(%edi)
 8048106:       6c                      insb   (%dx),%es:(%edi)
 8048107:       6f                      outsl  %ds:(%esi),(%dx)
 8048108:       21 00                   and    %eax,(%eax)
-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
Post Reply