A lazy man's compatibility library

onre

Administrator
Feb 8, 2019
59
18
8
I've thought of this a lot. It'd need #include_next to work transparently so that part is GCC only, but it could be usable with MIPSpro too with minimal patching to the source being compiled.

Features which could be easily done:
  • anonymous MMAP emulation through opening /dev/zero, creating the mmap and closing it
  • setenv/unsetenv
  • asprintf etc
  • mkdtemp
  • strerror_r
  • possibly being a horrible person and directly defining some symbols which are usually a PITA to dig from IRIX headers with #defines?
There's more, I'll update the list once I remember the ones I had in mind.

Discuss.
 
Last edited:

hammy

Member
Jun 1, 2019
65
32
18
UK
A little toy I built to see what is practical and whether something like gnulib makes it easy.

The skinny: Gnulib does make it easy to pull in pieces it has - but I've not extensively checked for the things @onre lists above.

This package is for now just a little test library that has a 'printf' replacement and a little test program that shows the replacement is working.

It only works with gcc (mipspro doesn't like to build the '.so' library using a '.a'), so it's far from anywhere near ok.

Might be inspiration for any actual effort.

See the "setupenv.sh" which should give an idea of the environment it expects for building. Run the "bootstrap.sh" to get autotools to initialise what it needs to.

Example symbols the library contains once built:

Code:
[dan@leafy libdicl]$ nm src/libdicl/.libs/libdicl-0.1.so.0.0.0  |grep rpl
5ffe4e90 T rpl_frexp
5ffe5200 T rpl_frexpl
5ffe5860 T rpl_printf
5ffe7550 T rpl_select
5ffe8140 T rpl_sprintf
5ffe8290 T rpl_strerror
5ffe8c9c T rpl_strtod
5fff0fd0 T rpl_vfprintf
5fff1160 T rpl_vsprintf
It installs a replacement "stdio.h" for the actual replacement. Example:

Code:
[dan@leafy libdicl]$ cat src/stdio.h
#ifndef LIBDICL_STDIO_H
#define LIBDICL_STDIO_H

#define printf rpl_printf

#warning "HAMSY We got in here!"

#include_next <stdio.h>

#endif
 
Last edited:

dexter1

New member
Jul 26, 2019
3
1
3
Zoetermeer, the Netherlands
It only works with gcc (mipspro doesn't like to build the '.so' library using a '.a'), so it's far from anywhere near ok.
Most likely you need to compile your objects with -KPIC and build your .so with ld -shared -all archive.a -o archive.so

Having said that, mktime() and strtod() frequently fail unittests on MIPSPro compilers, so i have replacements for those two.
 
  • Like
Reactions: hammy

hammy

Member
Jun 1, 2019
65
32
18
UK
Thanks dexter. Got it working with MIPSPro and gcc now (used -fPIC -DPIC plus the -all to the linker you mentioned).

Idea being the library itself is compiled with MIPSPro (so usable from both MIPSPro and GCC).

The replacement header uses either absolute include chains (MIPSPro) or include_next (GCC).

With my little tester (exercises printfs that hard fail without it) -

MIPSPro result using MIPSPro library:
Code:
[dan@leafy dicltester]$ env |grep CC
CC=c99
[dan@leafy dicltester]$ ./src/dicltester/dicltester
Dicltester called.
libdicl version is -> libdicl 0.1.0
printf is printf
The size_t with %ld is 0
The size_t with %zd is 0
The ptrdiff_t with %ld is 0
The ptrdiff_t with %td is 0
GCC result using MIPSPro library:
Code:
[dan@leafy dicltester]$ env |grep CC
CC=gcc
[dan@leafy dicltester]$ ./src/dicltester/dicltester
Dicltester called.
libdicl version is -> libdicl 0.1.0
printf is printf
The size_t with %ld is 0
The size_t with %zd is 0
The ptrdiff_t with %ld is 0
The ptrdiff_t with %td is 0
 

hammy

Member
Jun 1, 2019
65
32
18
UK
For anyone interested - this library is included inside "didbs" - and the list of "replacements" or additional functionality can be found here.

The headers where they get exposed are under https://github.com/danielhams/dicl/tree/master/libdicl/src/repl_headers

Care: depending on the build tool (autoconf, cmake etc) - these headers may be overlooked during "discovery" and you may need to force said tool to make the right choice (e.g. even though there is a "new" printf, autoconf goes to great lengths to `#undef` any macros before testing `printf` - which is no good - you have to override that with an appropriate parameter).

For the moment I offer little to no support. If you are using this, you get to keep the pieces.
 
Last edited:
  • Like
Reactions: Elf

About us

  • Silicon Graphics User Group (SGUG) is a community for users, developers, and admirers of Silicon Graphics (SGI) products. We aim to be a friendly hobbyist community for discussing all aspects of SGIs, including use, software development, the IRIX Operating System, and troubleshooting, as well as facilitating hardware exchange.

User Menu