Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Iostream Problem

Altera_Forum
Honored Contributor II
1,807 Views

Hi all,

 

I have recently posted a problem in the General Software Forum that I now know

applies to more specifically when using the eCos library. Here are the posts:

 

Hi,

 

I have recently been using the Nios II v6.0 tools and downloaded and installed

the eCos implementation for Neos. I went through the documentation for creating

the eCos library and building and running the examples included with eCos. All

worked fine. Then, I started slowly porting some existing code to the new platform

and ran into some issues. For the sake of narrowing down the problems, I went

back to the eCos examples and created a new file, hello.cpp:

 

/* this is a simple hello world program */

#include <iostream>

 

using namespace std;

 

int main(void)

{

cout << "Hello, eCos world!" << endl;

return 0;

}

 

The file compiles fine, but I get an error on the link:

 

nios2-elf-gcc -nostartfiles -L/cygdrive/c/altera/ecos/eqam_install/lib -Ttarget.ld -g -nostdlib -Wl,--gc-sections -Wl,-static -mhw-mul -mno-hw-mulx -mno-hw-div -o hello hello.o -lstdc++

/cygdrive/c/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/lib/libstdc++.a(ios_init.o)(.text+0x31c): In function `std::ios_base::sync_with_stdio(bool)&#39;:

/build/nios2/bin/nios2-gnutools/src/gcc/libstdc++-v3/libsupc++/new:92: undefined reference to `_impure_ptr&#39;

/cygdrive/c/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/lib/libstdc++.a(ios_init.o)(.text+0x31c):/build/nios2/bin/nios2-gnutools/src/gcc/libstdc++-v3/libsupc++/new:92: Unable to reach _impure_ptr (at 0x00000000) from the global pointer (at 0x04041e7c) because the offset (-67378812) is out of the allowed range, -32678 to 32767.

 

Any help that could be provided would be greatly appreciated.

 

Thanks!

Rennie

 

P.S. For the sake of completeness, here&#39;s the compiler command and output:

 

nios2-elf-gcc -c -o hello.o -I/cygdrive/c/altera/ecos/eqam_install/include -g -O3 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fvtable-gc -DSYSTEM_BUS_WIDTH=32 -mhw-mul -mno-hw-mulx -mno-hw-div hello.cpp

cc1plus: warning: switch "-fvtable-gc" is no longer supported 

 

================================================== ===

 

Hi all,

 

More information...

 

<attachment>

 

If anyone has a suggestion, I would really appreciate it.

 

Thanks,

Rennie

 

================================================== ===

 

I recently built the hello_world example as C++, i.e., I renamed the file to

hello_world.cpp and changed the contents to:

 

/*

* "Hello World" example.

*

* This example prints &#39;Hello from Nios II&#39; to the STDOUT stream. It runs on

* the Nios II &#39;standard&#39;, &#39;full_featured&#39;, &#39;fast&#39;, and &#39;low_cost&#39; example

* designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT

* device in your system&#39;s hardware.

* The memory footprint of this hosted application is ~69 kbytes by default

* using the standard reference design.

*

* For a reduced footprint version of this template, and an explanation of how

* to reduce the memory footprint for a given application, see the

* "small_hello_world" template.

*

*/

 

//#include <stdio.h>

#include <iostream>

 

using namespace std;

 

int main()

{

// printf("Hello from Nios II!\n");

cout << "Hello from Nios II, iostream style!" << endl;

 

return 0;

}

 

If I build this as a Nios II only project (no eCos library specification), it builds

fine and runs fine. This implies that the problem lies with the use of iostream

functionality when using the eCos library that was built. I have followed the

instructions provided with the eCos installation for Nios II, but have not been

able to get past this problem. Any suggestions or help would be greatly

appreciated.

 

Thanks in advance!

Rennie

0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
992 Views

You&#39;re barking up the wrong tree assuming this is down to iostream, though I can see why you thought this. the problem is that the compiler is trying to use ab instruction which has a limit on how far it can reach. There is an option to tell the compiler not to use this sequence, though from memory I&#39;m not certain, but I think it&#39;s something like -relax-all

0 Kudos
Altera_Forum
Honored Contributor II
992 Views

i do not encounter this problem when i creat a .cpp project 

 

"Unable to reach _impure_ptr (at 0x00000000) from the global pointer (at 0x04041e7c) because the offset (-67378812) is out of the allowed range, -32678 to 32767."  

about this problom ,you check size of your memory
0 Kudos
Altera_Forum
Honored Contributor II
992 Views

 

--- Quote Start ---  

originally posted by mjl-0708@Jun 21 2006, 05:55 AM 

i do not encounter this problem when i creat a .cpp project 

 

"unable to reach _impure_ptr (at 0x00000000) from the global pointer (at 0x04041e7c) because the offset (-67378812) is out of the allowed range, -32678 to 32767."  

about this problom ,you check size of your memory 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=16311) 

--- quote end ---  

 

--- Quote End ---  

 

 

Are you using the eCos library installation during the compilation/link and is your 

application using the iostream library? 

 

More information: 

 

See this link: http://bugs.ecos.sourceware.org/show_bug.cgi?id=1000037 (http://bugs.ecos.sourceware.org/show_bug.cgi?id=1000037

Quote from the bottom of the page: 

 

------- Additional Comment# 2 From Jonathan Larmour 2003-07-31 04:13 [reply] -------  

libstdc++ (which implements iostreams) is not yet supported by eCos (a lot of 

the ground work is done, but funding had stopped and until it continues it will 

probably stay that way alas). Even if it was, it wouldn&#39;t be supported with 

synthetic target linux. At least not without a specially customised 

compiler/libstdc++ implementation. The problem with synth linux specifically is 

that the compiler makes assumptions that it&#39;s running with the Linux OS, when in 

fact we want it to run eCos (and eCos surreptitiously makes it work with the 

Linux kernel). 

 

However, I was able to get a little farther with this problem. I had to define 

_impure_ptr: 

 

#include <sys/reent.h> //-------------------------------------------------------------------------- // The newlib library uses an impure_data structure to keep track of global // variables which need to be unique for each thread. /* Note that there is a copy of this in sys/reent.h.  */# ifndef __ATTRIBUTE_IMPURE_PTR__# define __ATTRIBUTE_IMPURE_PTR__# endif # ifndef __ATTRIBUTE_IMPURE_DATA__# define __ATTRIBUTE_IMPURE_DATA__# endif static struct _reent __ATTRIBUTE_IMPURE_DATA__ impure_data = _REENT_INIT (impure_data); struct _reent *__ATTRIBUTE_IMPURE_PTR__ _impure_ptr = &impure_data; 

 

and define and initialize ctype: 

 

#define _U  01      //upper# define _L  02      //lower# define _N  04      //number# define _S  010     //space# define _P  020     //punctuation# define _C  040     //control# define _X  0100    //hex# define _B  0200    //blank char _ctype_; void init_ctype_() {    int i;    // First clear all values...    for ( i = 0; i < 257; i++ )    {        _ctype_ = 0;    }    // Punctuation.  This should be first so all non-punct characters have    // their values replaced.    for ( i = &#39;!&#39;; i <= &#39;~&#39;; i++ )    {        (_ctype_+1) = _P;    }    // Uppercase characters    for ( i = &#39;A&#39;; i <= &#39;Z&#39;; i++ )    {        (_ctype_+1) = _U;    }    // Lowercase characters    for ( i = &#39;a&#39;; i <= &#39;z&#39;; i++ )    {        (_ctype_+1) = _L;    }    // Numbers    for ( i = &#39;0&#39;; i <= &#39;9&#39;; i++ )    {        (_ctype_+1) = _N;    }    // Hex letters from a through f    for ( i = &#39;A&#39;; i <= &#39;F&#39;; i++ )    {        (_ctype_+1) |= _X;    }    for ( i = &#39;a&#39;; i <= &#39;f&#39;; i++ )    {        (_ctype_+1) |= _X;    }    // Space characters    (_ctype_+1)  = _S | _B;    (_ctype_+1) = _S;    (_ctype_+1) = _S;    (_ctype_+1) = _S;    (_ctype_+1) = _S;    (_ctype_+1) = _S;    // Control characters, including escape    for ( i = 0; i <= 31; i++ )    {        (_ctype_+1) = _C;    }    (_ctype_+1) = _C; } 

 

and define __errno(): 

 

#include <errno.h> int __errno() {    return errno; } 

 

and had to provide some stub functions to get everything to link: 

 

/* * write (fd, buf, nbytes) * */ void write(void) {  printf("write() function is stubbed out!\n"); } /* * fdopen() * */ int fdopen(void) {  printf("fdopen() function is stubbed out!\n");  return -1; } /* * fileno() * */ int fileno(void) {  printf("fileno() function is stubbed out!\n");  return -1; } /* * read( fd, buf, nbytes ) * */ void read(void) {  printf("read() function is stubbed out!\n"); } /* * lseek() * */ int lseek(void) {  printf("lseek() function is stubbed out!\n");  return -1; } /* * fstat() * */ int fstat(void) {  printf("fstat() function is stubbed out!\n");  return -1; } 

 

So now, I can build an application (compile and link), but when I run it, I don&#39;t 

get any of my cout output. I get printf output, but not the cout. For example, 

when I execute: 

 

printf("Hello, eCos world, printf-style!\n"); 

cout << "Hello, eCos world, cout-style" << endl; 

printf("Hello, eCos world, printf-style!\n"); 

 

At the console, I only get: 

 

Hello, eCos world, printf-style! 

Hello, eCos world, printf-style! 

 

Any ideas or suggestions? 

 

Thanks for the replies! 

Rennie
0 Kudos
Altera_Forum
Honored Contributor II
992 Views

More information: 

 

If I put in a call to sync_with_stdio() setting it to false, i.e., 

 

int main(void) {  ios::sync_with_stdio(false);  printf("Hello, eCos world, printf-style!\n");  cout << "Hello, eCos world, cout-style" << endl;  printf("Hello, eCos world, printf-style!\n");  return 0; } 

 

I now get as output: 

 

Hello, eCos world, printf-style! 

fileno() function is stubbed out! 

write() function is stubbed out! 

write() function is stubbed out! 

write() function is stubbed out! 

Hello, eCos world, printf-style! 

 

Implying that the cout is close to working, but that it uses 

the fileno() and write() functions that I have stubbed out 

(see earlier post). Does anyone know how to get at the 

"real" versions of these functions so that I can tie them in? 

 

(I believe this makes sense too, because the debug console 

is the JTAG uart port and would be using the write() function 

to accomplish the cout.) 

 

Thanks, 

Rennie 

 

P.S. I tried the same test using the MicroC/OS-II OS and 

also could not get the couts to work until I put in a call to 

ios::sync_with_stdio(false); 

So, I think I&#39;m on the right track... I just need to find the 

necessary underlying functions (write(), fileno(), etc?) to 

get it to work under eCos.
0 Kudos
Altera_Forum
Honored Contributor II
992 Views

Hi all, 

 

I got the iostreams library to work! 

 

JFYI, 

Rennie
0 Kudos
Reply