Arm Community
Site
Search
User
Site
Search
User
Groups
Research Collaboration and Enablement
DesignStart
Education Hub
Innovation
Open Source Software and Platforms
Forums
AI and ML forum
Architectures and Processors forum
Arm Development Platforms forum
Arm Development Studio forum
Arm Virtual Hardware forum
Automotive forum
Compilers and Libraries forum
Graphics, Gaming, and VR forum
High Performance Computing (HPC) forum
Infrastructure Solutions forum
Internet of Things (IoT) forum
Keil forum
Morello Forum
Operating Systems forum
SoC Design and Simulation forum
中文社区论区
Blogs
AI and ML blog
Announcements
Architectures and Processors blog
Automotive blog
Graphics, Gaming, and VR blog
High Performance Computing (HPC) blog
Infrastructure Solutions blog
Innovation blog
Internet of Things (IoT) blog
Operating Systems blog
Research Articles
SoC Design and Simulation blog
Tools, Software and IDEs blog
中文社区博客
Support
Arm Support Services
Documentation
Downloads
Training
Arm Approved program
Arm Design Reviews
Community Help
More
Cancel
Support forums
Arm Development Studio forum
Char array and .data section
Jump...
Cancel
Locked
Locked
Replies
8 replies
Subscribers
121 subscribers
Views
5359 views
Users
0 members are here
Options
Share
More actions
Cancel
Related
How was your experience today?
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion
Char array and .data section
Offline
Arifa Khan
over 9 years ago
Note: This was originally posted on 11th January 2011 at
http://forums.arm.com
Hi,
I've been trying to use string literals in my C code, however I'm having a really odd problem.
I've condensed my code to do just a basic store string literal in a char variable, and output element value:
Code 1:
#include "generic.h"
#include "stdlib.h"
#include "string.h"
int main(void) {
char chartest[4]="HEL";
uart_send_num(chartest[2]); //function I've written to output the numeric value of data, to my serial port
}
Result 1:
0076
So that result is what I expected to see (ASCII : L = 76).
If I change the array size to anything bigger than 4 elements:
Code 2:
#include "generic.h"
#include "stdlib.h"
#include "string.h"
int main(void) {
char chartest[5]="HELL";
uart_send_num(chartest[2]);
}
Result 2:
0000
I can't understand why this would be happening.
I'm using Codesourcery gcc with Eclipse SDK, but still trying to figure out how everything works, so I haven't got all the libraries and maybe even linker script working correctly, i.e. printf, malloc, etc. doesn't work, therefore I wrote my own uart routine.
Part of my linker script is as follows:
.text : {
CREATE_OBJECT_SYMBOLS
*(.text .stub .text.* .gnu.linkonce.t.*)
*(.plt)
*(.gnu.warning)
*(.glue_7t) *(.glue_7) /* NOTE: placed already in .fastcode */
. = ALIGN (4);
/* These are for static constructors and destructors under ELF */
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
*(.rodata .stub .rodata.* .gnu.linkonce.r.*)
*(.ARM.extab* .gnu.linkonce.armextab.*)
*(.gcc_except_table)
*(.eh_frame_hdr)
*(.eh_frame)
*(.init)
*(.fini)
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
} >ROM
/* .ARM.exidx is sorted, so has to go in its own output section. */
.ARM.exidx : {
__exidx_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
__exidx_end = .;
} >ROM
_etext = .;
.data : {
ram_sdata = .;
__data_load = LOADADDR (.data);
__data_start = .;
KEEP(*(.jcr))
*(.got.plt) *(.got)
*(.shdata)
PROVIDE(_sdata = . );
*(.data .stub .data.* .gnu.linkonce.d.*)
. = ALIGN(4);
. = ALIGN (4);
PROVIDE(_edata = . );
_edata = .;
} >RAM AT>ROM
.bss : {
__bss_start = . ;
*(.shbss)
*(.bss .stub .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN (4);
PROVIDE(_sbss = . );
*(.bss)
. = ALIGN(4);
PROVIDE(_ebss = . );
__bss_end = .;
} >RAM
PROVIDE(__heap_start__ = __bss_end );
__HEAPSIZE__ = 4097;
I'm presuming it's something to do with my linker script?
I've tried searching for a similar problem, but nothing relevant seems to come up. Would anyone have any suggestions or ideas on what may be the problem?
At this point, even any guesses would be more than welcome!
Thanks!
Parents
Offline
Arifa Khan
over 9 years ago
Note: This was originally posted on 12th January 2011 at
http://forums.arm.com
I would also try
const char chartest[5]="HELL";
to see what happens.
Had tried that too.
It doesn't work.
So arrays over 4 elements don't work. Pointers don't work. Something to do with data allocation...?
Cancel
Up
0
Down
Cancel
Reply
Offline
Arifa Khan
over 9 years ago
Note: This was originally posted on 12th January 2011 at
http://forums.arm.com
I would also try
const char chartest[5]="HELL";
to see what happens.
Had tried that too.
It doesn't work.
So arrays over 4 elements don't work. Pointers don't work. Something to do with data allocation...?
Cancel
Up
0
Down
Cancel
Children
No data