[Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space

Pham, Phong phamp at ddc-web.com
Wed May 2 02:32:48 CEST 2018


Hi Philippe,

Below are the snippets compiled with -fPIC in the DSO.  If I don't compile with -fPIC, I get this error:

# bin/vxapp
bin/vxapp: error while loading shared libraries: /usr/xenomai/lib/libscs750.so: R_PPC_REL24 relocation at 0x0ffacec4 for symbol `munmap' out of range

If I do compile with -fPIC for my DSO, this is the snippet on the executable (ie. from your example, that would be "vxapp" executable.)

...
...
        int fd_eeprom = open("/dev/rtdm/eeprom,mapper0", O_RDWR);
        uint32_t baseAddr_eeprom = (volatile uint32_t)mmap(NULL, SCS_EEPROM_PHYSICAL_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd_eeprom, 0);
printf("%s():  baseAddr_eeprom = 0x%08x\n", __func__, baseAddr_eeprom);
...
...

Below is the snippet from my DSO:

...
...
    int fdm = open("/dev/rtdm/eeprom,mapper0", O_RDWR);
    uint32_t baseAddr = -2;

printf("%s(): baseAddr = 0x%08x, errno = %d\n", __func__, baseAddr, errno);
baseAddr = (volatile uint32_t)mmap(NULL, SCS_EEPROM_PHYSICAL_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fdm, 0);

if (baseAddr = -1)
{
printf("%s(): baseAddr = 0x%08x, errno = %d\n", __func__, baseAddr, errno);
}
....

For my DSO, LDFLAGS := $(shell $(XENO_CONFIG) --no-auto-init --posix --vxworks --ldflags) is in the makefile.  For my "vxapp", LDFLAGS := $(shell $(XENO_CONFIG) --posix --vxworks --ldflags)

Output:
scsEepromTest():  baseAddr_eeprom = 0x366ee000
sysEepromSet(): baseAddr = 0xfffffffe, errno = 0
sysEepromSet(): baseAddr = 0xffffffff, errno = 0

scsEepromTest() resides in the "vxapp" executable and sysEepromSet() resides in the DSO.

Phong.

-----Original Message-----
From: Philippe Gerum [mailto:rpm at xenomai.org]
Sent: Thursday, April 19, 2018 12:26 AM
To: Pham, Phong; xenomai at xenomai.org
Cc: Hillman, Robert
Subject: Re: [Xenomai] mmap when using in conjunction with mapper to retrieve memory mapped IO space

On 04/19/2018 01:02 AM, Pham, Phong wrote:
> “This is likely happening because the default auto-init glue module for
> a final executable is mentioned in the flags, you either want to pass
> --auto-init-solib if you do need auto-init for bootstrapping a DSO, or
> --no-auto-init if you don't care about auto-bootstrap, along with
> --ldflags to xeno-config.
>
>
>
> http://www.xenomai.org/documentation/xenomai-3/html/man1/xeno-config/index.html“
>
>
>
>
>
> I see.  After adding either --auto-init-solib or --no-auto-init when
> compiling for library, along with compiler option -fPIC, mmap() still
> returns -1; (W/out -fPIC, munmap() cannot be relocated (similar types of
> error like before).

xeno-config --ldflags will return the Xenomai-related flags for linking,
which -fPIC is not. If you plan for building a DSO, you need to apply
the common rules stated in the ld documentation, which include
mentioning  -fPIC / -fpic for shared libs. This is not a Xenomai issue.

  However, errno is 0.  How come errno returns “no
> error” when mmap() returns failure?
>

Please post a test code snippet illustrating the problem.

--
Philippe.
Notice: This e-mail and any files transmitted with it may contain Data Device Corporation's privileged and proprietary information. It is intended solely for the use of the individual or entity to whom it is addressed. If you are not the named recipient of this transmission, any disclosure, copying, distribution or reliance on the contents of this message is prohibited. If you received this e-mail in error, please destroy it and any attached files and notify me immediately.


More information about the Xenomai mailing list