LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-13-2010, 01:27 AM   #1
Richard.Yang
Member
 
Registered: Sep 2008
Posts: 106

Rep: Reputation: 16
Some one got know how to write a lds(linker script) file?


Hi, all

I first found something called lds(linker script) file.

And now I am willing to do a test with __attribute__((section)) to make a function stay in a private section. Sounds fun to me.

Part of my source code looks like this
typedef struct A
{
int a;
}A;
A a __attribute__((section ("my_own")));

By objdump, I didn't find a section called "my_own".
So I guess the lds is needed. Anyone got some idea on this?
Or I approach is impossible?
 
Old 10-13-2010, 01:46 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Works fine for me. Specifically:
Code:
#include <stdio.h>

struct A
{
  int a, b;
};

struct A a __attribute ((section ("my_own")));

int
main (int argc, char *argv[])
{
  a.a = 1;
  a.b = 2;
  return 0;
}
Code:
gcc -c tmp.c

objdump -h tmp.o
tmp.o:     file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000002d  00000000  00000000  00000034  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000064  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000064  2**2
                  ALLOC
  3 my_own        00000008  00000000  00000000  00000064  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  4 .comment      0000002e  00000000  00000000  0000006c  2**0
                  CONTENTS, READONLY
  5 .note.GNU-stack 00000000  00000000  00000000  0000009a  2**0
                  CONTENTS, READONLY

gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Old 10-14-2010, 02:30 AM   #3
Richard.Yang
Member
 
Registered: Sep 2008
Posts: 106

Original Poster
Rep: Reputation: 16
Thanks for you answer. I see this too.

BTW, I use
gcc tmp.c -o tmp
objdump -S tmp > tmp.s

In the tmp.s, I couldn't find a section called "my_own". Even the .bss and .data section.
Do you know the reason?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write a script file shravee Linux - Newbie 12 04-18-2010 09:17 AM
linker script file not found while using codesourcery g++ lite to program a developme raphtor Linux - Software 0 10-21-2009 04:04 AM
Can you write a script to display file name, Inode, and size of any file? JaxsunApex Linux - Newbie 3 01-30-2007 08:39 AM
How to write script file in Linux? rust8y Linux - General 3 05-20-2006 05:49 AM
Backup script to write to file? ctroyp Linux - Newbie 13 01-10-2006 06:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration