This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[doc] DSO HOWTO comments

Hallo, Ulrich Drepper. Cheers, developers.

Below is list of possible corrections. But first let me address
published way of generating forever const chat arrays
(partially sent privately on Sat Jun 16 11:35:41 2007)

== First turn ==

Let me propose another way of static read-only string generation.

Original C code in paper isn't only obfuscated, because you are
asking to look at preprocessor output, but doesn't compile. This is
example of course, but to compile that, one must do more magic. I did
enum generation for ERRX values, with yet another include. This also
isn't optimal, 4xfile access, from program compilation POV.

Yet after having it compiled, one may find, that there's no range
checking at all, thus that access function will easily lead to
`catastrophe'. And IMHO this isn't good for example code in such
comprehensive paper as yours.

Please, let me share with my view on that. Thanks.

Optimization step done is, that there're ERRX values as offset constants.
It's just to have efficient code size. The main point is that, while
glibc developers are very keen C, m4, makefile, sed gurus, yet that
published things are inefficient at all, while talk is about efficiency
and optimization. I've used only shell as you probably will see.

There's also a response from bzip2 author regarding such kind of

== Builder (processing of input): filename=Makefile ==
tst-static-const: static_const_strings.c err_strings.h
	gcc -pipe -Wall -o $@ $<

err_strings.h: strerrors.h
	cat $< | sh >$@

== Test: filename="static_const_strings.c" ==
#include "err_strings.h"
#include <stdio.h>

int main(void)

	/* bad range/corner cases */

	return 0;

== Input: filename="strerrors.h" ==
_S(NO_MESSAGE, "wrong error message index")
_S(ERR_ONE, "error  one")
_S(TWO, "two")
_S(ERR_3, "3 and last")

== Input processor: filename=""
#!/bin/sh -e
make_start() {
    str="$@" ; idx="${str#*(}" ; n=0
    idx="${idx%%,*}" ; str="${str#*\"}" ; str="${str%\"*}"
    printf '/* automaticly generated read only string array */
#define %s	(0U)
static const char err_strings[] =' "$idx"
make_element() {
    nstr="$@" ; idx="${nstr#*(}" ; n=$(($n + ${#str} + 1))
    idx="${idx%%,*}" ; nstr="${nstr#*\"}" ; newstr="${nstr%\"*}"
    printf '
#define %s	(%sU)' "$str" "$idx" "$n"

read -r LINE && make_start "$LINE"
while read -r LINE
do make_element "$LINE"
done && printf '
#define LAST	%s' "$str" "$idx"
echo "
const char* errstr(unsigned idx)
	idx = idx > LAST ? 0 : idx;

	return err_strings + idx;

== One Response ==

>From olecom Mon Jun 18 20:43:27 2007
Date: Mon, 18 Jun 2007 20:43:27 +0200
To: Julian Seward <>
Subject: Re: libbz2: More const optimizations

On Mon, Jun 18, 2007 at 02:32:18PM +0100, Julian Seward wrote:
> Well, this is a Linux specific optimisation, yes?

To have one static read-only string with offsets, that can be coded to
assembler commands directly, instead of static array of pointers to const
string is optimization on every software/hardware, regardless of platform
and shared library implementation/static binary, i think.

> Remember bzip2 is intended for all platforms, not just Linux, that is
> the problem.

== DSO correction list ==

If you don't mind, here are possible corrections to v.4.0. of your fine
DSO HOWTO. Thanks for reading, BTW!

p.01 - "But the parts the user directly has to deal with __created
        initially problems__" -> "create initial problems" ||
                                 "create problems initially"

p.10 - "...DSOs are loaded dynamic{ally} using dlopen"

p.13 - "This directly translates to fewer system call{s}"

-"-  - "In general __does __the dynamic linker have..." -> ____

p.17 - "Failing to restrict the set of exported symbols __are __
        numerous drawbacks:" -> __leads to__?

-"-  - "The easiest way to not export a variable or function is to
       __the define it file__ file-local scope" -> __define__

p.18 - "If it is not used, symbols which are not..." -> If it is not
       used, unexported symbols must be marked as described below.
       (What is the other way? ;)

p.19 - "Instead of adding _an__ visibility" -> __a__

p.28 - "structuring such tables __is__ appendix B" -> __see__ ||
       __there is___

p.30 skipped

p.31 - undefined reference to "foobar"

Good bye.
 #oo'L O
<___=E M

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]