Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8533463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:58:15+00:00 2026-06-11T09:58:15+00:00

I have the following string declared as a constant in my code. The purpose

  • 0

I have the following string declared as a constant in my code. The purpose is to provide a crude and simple way of storing simple metadata in the compiled output.

const char myString1[] ="abc123\0";
const char myString2[] = {'a','b','c','1','2','3','\0'};

When I inspect the output with a hex editor, I see other string constants but “abc123” does not appear. This leads me to believe that the optimizations that are enabled are causing the lines not to be compiled, as they are never referenced in the program.

Is there a way in code to force this to compile, or another way (in code) of getting this metadata into the binary? I don’t want to do any manipulation of the binary post-compile, the goal is to keep it as simple as possible.

compiler flags

-O2 -g -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -mcpu=cortex-m3 -mthumb

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:58:17+00:00Added an answer on June 11, 2026 at 9:58 am

    I’ve come up with a solution that uses attributes and involves modifying the link script.

    First I define a custom section called “.metadata”.

    __attribute__ ((section(".metadata")))
    

    Then, in the SECTIONS block of the .ld script I added a KEEP(*(.metadata)) which will force the linker to include .metadata even if it’s not used

    .text :
    {
        KEEP(*(.isr_vector))
        KEEP(*(.metadata))
        *(.text*)
        *(.rodata*)
    
    } > MFlash32
    

    NOTE

    I found that the __attribute__ keyword had to be on the same line as the variable or else it didn’t actually show up in the binary, though the .metadata section did show up in the memory map.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code li1 = ddsState.Items.FindByValue(State) I declared li1 as String but
I have the following Java code: String query = Select 1 from myTable where
I have the following code snippet. public static void main(String[] args) { short a
I have got the following code #include <iostream> #include <string> template <typename T> class
I have the following code: //Comp454 program 2 #include <iostream> #include <string> #include <fstream>
I have the following string declared in strings.xml: <string name=last_msg>Your last click was on</string>
Have following code: public interface ITest { string St1 { get; } } public
I have the following code: #include <string> #include <boost/thread/tss.hpp> static boost::thread_specific_ptr<string> _tssThreadNameSptr; I get
I have the following C code which works: #include <stdio.h> #include <stdlib.h> #include <string.h>
I have the following code Case "Formula_MDX" Dim cubeid As String = Request("intCubeId") Dim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.