The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] tool (that wnj wrote?) that reduced the data segment size?
@ 2015-11-28 23:30 Norman Wilson
  2015-11-28 23:38 ` Charles Anthony
  0 siblings, 1 reply; 9+ messages in thread
From: Norman Wilson @ 2015-11-28 23:30 UTC (permalink / raw)


I'm too tired to dig for the exact words in the ISO standard,
but I had the impression that the official C rule these days
is that the effect of writing on a string literal is undefined.

So it's legal for an implementation to make strings read-only,
or to point several references to "What's the recipe today, Jim"
to one copy of the stripng in memory, and even to point uses of
"Jim" to the tail of the same string.  Or both.

It is also legal for every string literal to reside in its own
memory and to be writable, but since the effect is undefined,
code that relies on that is on thin ice, especially if meant to
be portable code.

I have used, and even fixed (unrelated) bugs in, a compiler
that merged identical strings.  I forget whether it also looked
for suffix matches.  Whether the strings went in read-only
memory was up to the code generator (of course); in the new
back-end I wrote for it, I made them so.  This turned up quite a
few fumbles in very-old UNIX code that assumed unique, writable
string literals, especially those that called mktemp(3).  To my
mind that just meant the programs needed to be fixed to match
current standards (just as many old programs needed fixes to
compile without error in ISO C), so I fixed them.

I didn't (and still don't) like Joy's heavy-handed hack, but I
see his point, and think it's just fine for the language rules
to allow the compiler to do it hacklessly.

Norman Wilson
Toronto ON



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [TUHS] tool (that wnj wrote?) that reduced the data segment size?
  2015-11-28 23:30 [TUHS] tool (that wnj wrote?) that reduced the data segment size? Norman Wilson
@ 2015-11-28 23:38 ` Charles Anthony
  2015-11-30  3:07   ` John Cowan
  0 siblings, 1 reply; 9+ messages in thread
From: Charles Anthony @ 2015-11-28 23:38 UTC (permalink / raw)


On Sat, Nov 28, 2015 at 3:30 PM, Norman Wilson <norman at oclsc.org> wrote:

>
> I didn't (and still don't) like Joy's heavy-handed hack, but I
> see his point, and think it's just fine for the language rules
> to allow the compiler to do it hacklessly.
>
>
IIRC, in "The Design of an Optimizing Compiler", it says something like:

"The Optimizing Compiler Writer's Motto: It is no sin to make a wrong
program worse."

-- Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20151128/ad9a22a4/attachment.html>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [TUHS] tool (that wnj wrote?) that reduced the data segment size?
  2015-11-28 23:38 ` Charles Anthony
@ 2015-11-30  3:07   ` John Cowan
  2015-11-30  5:38     ` Nick Downing
  0 siblings, 1 reply; 9+ messages in thread
From: John Cowan @ 2015-11-30  3:07 UTC (permalink / raw)


Charles Anthony scripsit:

> "The Optimizing Compiler Writer's Motto: It is no sin to make a wrong
> program worse."

It is if the rules for which programs are wrong are essentially beyond
human comprehension on the fly.  Anyway: "That program has about a
thousand bugs.  Which would you rather, that we fixed all the bugs or
that we made it run a thousand times faster?"

-- 
John Cowan          http://www.ccil.org/~cowan        cowan at ccil.org
Heckler: "Go on, Al, tell 'em all you know.  It won't take long."
Al Smith: "I'll tell 'em all we *both* know.  It won't take any longer."



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [TUHS] tool (that wnj wrote?) that reduced the data segment size?
  2015-11-30  3:07   ` John Cowan
@ 2015-11-30  5:38     ` Nick Downing
  0 siblings, 0 replies; 9+ messages in thread
From: Nick Downing @ 2015-11-30  5:38 UTC (permalink / raw)


Guys I wrote a more modern version of xstr for a project (porting PDP11
utilities and games to a modern compiler for a different embedded system).
How it worked was similar to i18n utilities on a modern system. (I planned
to internationalize later). So what it did was remove any strings bracketed
with _("blah blah") to a strings file and then replace with a 32-bit
integer offset into the file. I had utilities like _printf(long off, ...)
which would access the strings file to get the necessary string and print
it, or just _strdup() which would bring it into memory where the programmer
could use as normal and free when done. What I did next was to have the
linker treat the strings file as a resource and merge it into the
executable, so that with a little trickery the strings could be directly
accessed from flash ROM while not taking any of the precious 64 kbytes RAM
in the program's data space. Happy to dig this up and share.
Nick
On 30/11/2015 2:26 PM, "John Cowan" <cowan at mercury.ccil.org> wrote:

> Charles Anthony scripsit:
>
> > "The Optimizing Compiler Writer's Motto: It is no sin to make a wrong
> > program worse."
>
> It is if the rules for which programs are wrong are essentially beyond
> human comprehension on the fly.  Anyway: "That program has about a
> thousand bugs.  Which would you rather, that we fixed all the bugs or
> that we made it run a thousand times faster?"
>
> --
> John Cowan          http://www.ccil.org/~cowan        cowan at ccil.org
> Heckler: "Go on, Al, tell 'em all you know.  It won't take long."
> Al Smith: "I'll tell 'em all we *both* know.  It won't take any longer."
> _______________________________________________
> TUHS mailing list
> TUHS at minnie.tuhs.org
> https://minnie.tuhs.org/mailman/listinfo/tuhs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20151130/db77d327/attachment.html>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [TUHS] tool (that wnj wrote?) that reduced the data segment size?
  2015-11-28  0:03   ` Larry McVoy
@ 2015-11-30  2:45     ` Erik E. Fair
  0 siblings, 0 replies; 9+ messages in thread
From: Erik E. Fair @ 2015-11-30  2:45 UTC (permalink / raw)


The xstr(1) program is still maintained in the NetBSD distribution.
It's not a part of the C compiler - it's much more akin to a C
pre-processor:

	http://man.netbsd.org/7.0/usr/share/man/html1/xstr.html

See also mkstr(1):

	http://man.netbsd.org/7.0/usr/share/man/html1/mkstr.html

As ham-handed as these tools are, they can be used for input to
manual programmer string storage reduction.

	Erik <fair at netbsd.org>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [TUHS] tool (that wnj wrote?) that reduced the data segment size?
@ 2015-11-28 14:58 Doug McIlroy
  0 siblings, 0 replies; 9+ messages in thread
From: Doug McIlroy @ 2015-11-28 14:58 UTC (permalink / raw)


> Woe betide the user if any string was changed at run time...

That was then. Now it would be OK to do so for const data.
(Unless the tool chain has discarded const indications.)

Doug



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [TUHS] tool (that wnj wrote?) that reduced the data segment size?
  2015-11-27 23:44 ` Dave Horsfall
@ 2015-11-28  0:03   ` Larry McVoy
  2015-11-30  2:45     ` Erik E. Fair
  0 siblings, 1 reply; 9+ messages in thread
From: Larry McVoy @ 2015-11-28  0:03 UTC (permalink / raw)


On Sat, Nov 28, 2015 at 10:44:58AM +1100, Dave Horsfall wrote:
> On Fri, 27 Nov 2015, Larry McVoy wrote:
> 
> > I've gotten sucked into an embedded system project and they are running 
> > out of memory.  I have a vague memory of some sort of tool that I think 
> > Bill Joy wrote (or maybe he told me about it) that would do some magic 
> > processing of all the string constants and somehow it de-dupped the 
> > space.
> > 
> > Though now that I'm typing this that doesn't seem possible.  Does this 
> > ring a bell with anyone?  I'm sure it was for the PDP 11 port.
> 
> I think you're referring to an abomination called "xstrings" (or "xstr"?).

Yup, that's it.  Cool, thanks.

> It was described by a colleague of mine as "about as subtle as a car 
> crash"; it worked by comparing strings at compilation time, even unto the 
> tails of said strings.
> 
> Woe betide the user if any string was changed at run time...

I get it.  I also get that I have 32KB of RAM and I'm down to my last 1.2KB.

--lm



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [TUHS] tool (that wnj wrote?) that reduced the data segment size?
  2015-11-27 22:26 Larry McVoy
@ 2015-11-27 23:44 ` Dave Horsfall
  2015-11-28  0:03   ` Larry McVoy
  0 siblings, 1 reply; 9+ messages in thread
From: Dave Horsfall @ 2015-11-27 23:44 UTC (permalink / raw)


On Fri, 27 Nov 2015, Larry McVoy wrote:

> I've gotten sucked into an embedded system project and they are running 
> out of memory.  I have a vague memory of some sort of tool that I think 
> Bill Joy wrote (or maybe he told me about it) that would do some magic 
> processing of all the string constants and somehow it de-dupped the 
> space.
> 
> Though now that I'm typing this that doesn't seem possible.  Does this 
> ring a bell with anyone?  I'm sure it was for the PDP 11 port.

I think you're referring to an abomination called "xstrings" (or "xstr"?).

It was described by a colleague of mine as "about as subtle as a car 
crash"; it worked by comparing strings at compilation time, even unto the 
tails of said strings.

Woe betide the user if any string was changed at run time...

It ranks right up there with nargs() as What Not To Do.

-- 
Dave Horsfall DTM (VK2KFU)  "Those who don't understand security will suffer."



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [TUHS] tool (that wnj wrote?) that reduced the data segment size?
@ 2015-11-27 22:26 Larry McVoy
  2015-11-27 23:44 ` Dave Horsfall
  0 siblings, 1 reply; 9+ messages in thread
From: Larry McVoy @ 2015-11-27 22:26 UTC (permalink / raw)


I've gotten sucked into an embedded system project and they are running out of
memory.  I have a vague memory of some sort of tool that I think Bill Joy
wrote (or maybe he told me about it) that would do some magic processing of
all the string constants and somehow it de-dupped the space.

Though now that I'm typing this that doesn't seem possible.  Does this ring
a bell with anyone?  I'm sure it was for the PDP 11 port.

Thanks,

--lm



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-11-30  5:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-28 23:30 [TUHS] tool (that wnj wrote?) that reduced the data segment size? Norman Wilson
2015-11-28 23:38 ` Charles Anthony
2015-11-30  3:07   ` John Cowan
2015-11-30  5:38     ` Nick Downing
  -- strict thread matches above, loose matches on Subject: below --
2015-11-28 14:58 Doug McIlroy
2015-11-27 22:26 Larry McVoy
2015-11-27 23:44 ` Dave Horsfall
2015-11-28  0:03   ` Larry McVoy
2015-11-30  2:45     ` Erik E. Fair

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).