Hello, This is a proposal for implementing "module flags". Please take a look at this and give any feedback you may have. Thanks! -bw Module Flags Metadata Information about the module as a whole is difficult to convey to LLVM's subsystems. The LLVM IR isn't sufficient to transmit this information. One should instead use the llvm.module.flags named metadata. These flags are in the form of a key / value pair -- much like a dictionary -- making it easy for any subsystem who cares about a flag to look it up. The llvm.module.flags metadata contains a list of metadata triplets. Each triplet has the following form: - The first element is a "behavior" flag, which specifies the behavior when two (or more) modules are merged together, and it encounters two (or more) metadata with the same ID. The supported behaviors are described below. - The second element is a metadata string that is a unique ID for the metadata. How each ID is interpreted is documented below. - The third element is the value of the metadata. When two (or more) modules are merged together, the resulting llvm.module.flags metadata is the union of the modules' llvm.module.flags metadata. The only exception being a flag with the 'Override' behavior, which may override another flag's value (see below). The following behavior flags are supported: Value Behavior ----- -------- 1 Error Emits an error if two values disagree. 2 Warning Emits a warning if two values disagree. 3 Require Emits an error when the specified value is not present or doesn't have the specified value. It is an error for two (or more) llvm.module.flags with the same ID to have the Require behavior but different values. There may be multiple Require flags per ID. 4 Override Uses the specified value if the two values disagree. It is an error for two (or more) llvm.module.flags with the same ID to have the Override behavior but different values. An example of module flags: !0 = metadata !{ i32 1, metadata !"foo", i32 1 } !1 = metadata !{ i32 4, metadata !"bar", i32 37 } !2 = metadata !{ i32 2, metadata !"qux", i32 42 } !3 = metadata !{ i32 3, metadata !"qux", metadata !{ metadata !"foo", i32 1 } } !llvm.module.flags = !{ !0, !1, !2, !3 } - Metadata !0 has the ID !"foo" and the value '1'. The behavior if two or more !"foo" flags are seen is to emit an error if their values are not equal. - Metadata !1 has the ID !"bar" and the value '37'. The behavior if two or more !"bar" flags are seen is to use the value '37' if their values are not equal. - Metadata !2 has the ID !"qux" and the value '42'. The behavior if two or more !"qux" flags are seen is to emit a warning if their values are not equal. - Metadata !3 has the ID !"qux" and the value: metadata !{ metadata !"foo", i32 1 } The behavior is to emit an error if the llvm.module.flags does not contain a flag with the ID !"foo" that has the value '1'. If two or more !"qux" flags exist, then they must have the same value or an error will be issued. Objective-C Metadata -------------------- To correctly link two or more Objective-C modules, the linker needs to know quite a bit of information about the language and how the modules were compiled. These flags are concerned with ABI versions and garbage collection, since they cannot conflict. The MachO writer uses these values to generate the "image info" section, and merges the values from different modules in an "intelligent" fashion rather than append them together. The supported names are: * Objective-C Version - The version of the Objective-C ABI. Valid values are '1' and '2'. It's an error for two or more Objective-C Version flags to have different values. * Objective-C Garbage Collection Version - The garbage collection version, used by the image info section. Currently always '0'. It is an error for two or more "Objective-C Garbage Collection Value" flags to have different values. * Objective-C Garbage Collection - Specifies that this module supports garbage collection. Valid values are '0' and '2'. A flag with the value of '0' will override one with the value of '2'. * Objective-C GC Only - Specifies that this module requires garbage collection. This requires that the "Objective-C Garbage Collection" metadata is present and has a value of '2'. If present the valid value is '4'. * Objective-C Image Info Section - The image info section holds information about Objective-C garbage collection. The "Objective-C Image Info Section" specifies the name of the section where the image info is placed. This flag is required if the "Objective-C Garbage Collection" flag is present and has the value of '2'. It is an error for two or more of these flags to have different values. Here is an example of how to use the Objective-C metadata: Module A -------- !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", metadata !{ metadata !"Objective-C Image Info Section", metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } } !4 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } !llvm.module.flags = !{ !0, !1, !2, !3, !4 } Module B -------- !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", metadata !{ metadata !"Objective-C Image Info Section", metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } } !4 = metadata !{ i32 1, metadata !"Objective-C GC Only", i32 4 } !5 = metadata !{ i32 3, metadata !"Objective-C GC Only", metadata !{ metadata !"Objective-C Garbage Collection", i32 2 } } !6 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } !llvm.module.flags = !{ !0, !1, !2, !3, !4, !5, !6 } Linked Module ------------- !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", metadata !{ metadata !"Objective-C Image Info Section", metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } } !4 = metadata !{ i32 1, metadata !"Objective-C GC Only", i32 4 } !5 = metadata !{ i32 3, metadata !"Objective-C GC Only", metadata !{ metadata !"Objective-C Garbage Collection", i32 2 } } !6 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } !llvm.module.flags = !{ !0, !1, !2, !3, !4, !5, !6 }
On Jan 18, 2012, at 1:36 PM, Bill Wendling wrote:> Hello, > > This is a proposal for implementing "module flags". Please take a look at this and give any feedback you may have. >To clarify, the "Objective-C Metadata" section is meant to act as an example implementation of the module flags metadata. (It was the impetus for me to start on this project.) In the LangRef.html document, it would be documented as a subsection of the Module Flags Metadata section. Similarly, additional uses (e.g., OpenCL) would be carefully documented in LangRef.html so that the semantics of the flags are clear. -bw
Could you expand on likely uses other than ObjC? For example, should float ABI (soft/softfp/hard) be conveyed via this mechanism? deep On Wed, Jan 18, 2012 at 9:36 PM, Bill Wendling <wendling at apple.com> wrote:> Hello, > > This is a proposal for implementing "module flags". Please take a look at this and give any feedback you may have. > > Thanks! > -bw > > Module Flags Metadata > > Information about the module as a whole is difficult to convey to LLVM's > subsystems. The LLVM IR isn't sufficient to transmit this information. One > should instead use the llvm.module.flags named metadata. These flags are in the > form of a key / value pair -- much like a dictionary -- making it easy for any > subsystem who cares about a flag to look it up. > > The llvm.module.flags metadata contains a list of metadata triplets. Each > triplet has the following form: > > - The first element is a "behavior" flag, which specifies the behavior when > two (or more) modules are merged together, and it encounters two (or more) > metadata with the same ID. The supported behaviors are described below. > > - The second element is a metadata string that is a unique ID for the > metadata. How each ID is interpreted is documented below. > > - The third element is the value of the metadata. > > When two (or more) modules are merged together, the resulting llvm.module.flags > metadata is the union of the modules' llvm.module.flags metadata. The only > exception being a flag with the 'Override' behavior, which may override another > flag's value (see below). > > The following behavior flags are supported: > > Value Behavior > ----- -------- > 1 Error > Emits an error if two values disagree. > > 2 Warning > Emits a warning if two values disagree. > > 3 Require > > Emits an error when the specified value is not present or > doesn't have the specified value. It is an error for two (or > more) llvm.module.flags with the same ID to have the Require > behavior but different values. There may be multiple Require > flags per ID. > > 4 Override > Uses the specified value if the two values disagree. It is an > error for two (or more) llvm.module.flags with the same ID to > have the Override behavior but different values. > > An example of module flags: > > !0 = metadata !{ i32 1, metadata !"foo", i32 1 } > !1 = metadata !{ i32 4, metadata !"bar", i32 37 } > !2 = metadata !{ i32 2, metadata !"qux", i32 42 } > !3 = metadata !{ i32 3, metadata !"qux", > metadata !{ > metadata !"foo", i32 1 > } > } > !llvm.module.flags = !{ !0, !1, !2, !3 } > > - Metadata !0 has the ID !"foo" and the value '1'. The behavior if two or more > !"foo" flags are seen is to emit an error if their values are not equal. > > - Metadata !1 has the ID !"bar" and the value '37'. The behavior if two or more > !"bar" flags are seen is to use the value '37' if their values are not equal. > > - Metadata !2 has the ID !"qux" and the value '42'. The behavior if two or more > !"qux" flags are seen is to emit a warning if their values are not equal. > > - Metadata !3 has the ID !"qux" and the value: > > metadata !{ metadata !"foo", i32 1 } > > The behavior is to emit an error if the llvm.module.flags does not contain a > flag with the ID !"foo" that has the value '1'. If two or more !"qux" flags > exist, then they must have the same value or an error will be issued. > > > Objective-C Metadata > -------------------- > > To correctly link two or more Objective-C modules, the linker needs to know > quite a bit of information about the language and how the modules were > compiled. These flags are concerned with ABI versions and garbage collection, > since they cannot conflict. The MachO writer uses these values to generate the > "image info" section, and merges the values from different modules in an > "intelligent" fashion rather than append them together. > > The supported names are: > > * Objective-C Version > - The version of the Objective-C ABI. Valid values are '1' and '2'. It's an > error for two or more Objective-C Version flags to have different values. > > * Objective-C Garbage Collection Version > - The garbage collection version, used by the image info section. Currently > always '0'. It is an error for two or more "Objective-C Garbage Collection > Value" flags to have different values. > > * Objective-C Garbage Collection > - Specifies that this module supports garbage collection. Valid values are > '0' and '2'. A flag with the value of '0' will override one with the value > of '2'. > > * Objective-C GC Only > - Specifies that this module requires garbage collection. This requires that > the "Objective-C Garbage Collection" metadata is present and has a value of > '2'. If present the valid value is '4'. > > * Objective-C Image Info Section > - The image info section holds information about Objective-C garbage > collection. The "Objective-C Image Info Section" specifies the name of the > section where the image info is placed. This flag is required if the > "Objective-C Garbage Collection" flag is present and has the value of > '2'. It is an error for two or more of these flags to have different > values. > > Here is an example of how to use the Objective-C metadata: > > Module A > -------- > !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } > !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } > !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } > !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", > metadata !{ > metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" > } > } > !4 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } > !llvm.module.flags = !{ !0, !1, !2, !3, !4 } > > Module B > -------- > !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } > !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } > !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } > !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", > metadata !{ > metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" > } > } > !4 = metadata !{ i32 1, metadata !"Objective-C GC Only", i32 4 } > !5 = metadata !{ i32 3, metadata !"Objective-C GC Only", > metadata !{ > metadata !"Objective-C Garbage Collection", i32 2 > } > } > !6 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } > !llvm.module.flags = !{ !0, !1, !2, !3, !4, !5, !6 } > > Linked Module > ------------- > !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } > !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } > !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } > !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", > metadata !{ > metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" > } > } > !4 = metadata !{ i32 1, metadata !"Objective-C GC Only", i32 4 } > !5 = metadata !{ i32 3, metadata !"Objective-C GC Only", > metadata !{ > metadata !"Objective-C Garbage Collection", i32 2 > } > } > !6 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } > !llvm.module.flags = !{ !0, !1, !2, !3, !4, !5, !6 } > > _______________________________________________ > cfe-dev mailing list > cfe-dev at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Hi Sandeep, ObjC is the first place that I will use it, of course (we need it to fix LTO). Other uses will come along later. (I don't know enough about the float ABI issues to say whether they should be done via module flags or not.) The OpenCL people have a need for named metadata for their stuff. I would hope that module flags would be a good fit for that, but that remains to be seen. But in general, any information which affects the module as a whole could use this feature. ObjC metadata is just an obvious first step. :-) -bw On Jan 19, 2012, at 9:12 AM, Sandeep Patel wrote:> Could you expand on likely uses other than ObjC? For example, should > float ABI (soft/softfp/hard) be conveyed via this mechanism? > > deep > > On Wed, Jan 18, 2012 at 9:36 PM, Bill Wendling <wendling at apple.com> wrote: >> Hello, >> >> This is a proposal for implementing "module flags". Please take a look at this and give any feedback you may have. >> >> Thanks! >> -bw >> >> Module Flags Metadata >> >> Information about the module as a whole is difficult to convey to LLVM's >> subsystems. The LLVM IR isn't sufficient to transmit this information. One >> should instead use the llvm.module.flags named metadata. These flags are in the >> form of a key / value pair -- much like a dictionary -- making it easy for any >> subsystem who cares about a flag to look it up. >> >> The llvm.module.flags metadata contains a list of metadata triplets. Each >> triplet has the following form: >> >> - The first element is a "behavior" flag, which specifies the behavior when >> two (or more) modules are merged together, and it encounters two (or more) >> metadata with the same ID. The supported behaviors are described below. >> >> - The second element is a metadata string that is a unique ID for the >> metadata. How each ID is interpreted is documented below. >> >> - The third element is the value of the metadata. >> >> When two (or more) modules are merged together, the resulting llvm.module.flags >> metadata is the union of the modules' llvm.module.flags metadata. The only >> exception being a flag with the 'Override' behavior, which may override another >> flag's value (see below). >> >> The following behavior flags are supported: >> >> Value Behavior >> ----- -------- >> 1 Error >> Emits an error if two values disagree. >> >> 2 Warning >> Emits a warning if two values disagree. >> >> 3 Require >> >> Emits an error when the specified value is not present or >> doesn't have the specified value. It is an error for two (or >> more) llvm.module.flags with the same ID to have the Require >> behavior but different values. There may be multiple Require >> flags per ID. >> >> 4 Override >> Uses the specified value if the two values disagree. It is an >> error for two (or more) llvm.module.flags with the same ID to >> have the Override behavior but different values. >> >> An example of module flags: >> >> !0 = metadata !{ i32 1, metadata !"foo", i32 1 } >> !1 = metadata !{ i32 4, metadata !"bar", i32 37 } >> !2 = metadata !{ i32 2, metadata !"qux", i32 42 } >> !3 = metadata !{ i32 3, metadata !"qux", >> metadata !{ >> metadata !"foo", i32 1 >> } >> } >> !llvm.module.flags = !{ !0, !1, !2, !3 } >> >> - Metadata !0 has the ID !"foo" and the value '1'. The behavior if two or more >> !"foo" flags are seen is to emit an error if their values are not equal. >> >> - Metadata !1 has the ID !"bar" and the value '37'. The behavior if two or more >> !"bar" flags are seen is to use the value '37' if their values are not equal. >> >> - Metadata !2 has the ID !"qux" and the value '42'. The behavior if two or more >> !"qux" flags are seen is to emit a warning if their values are not equal. >> >> - Metadata !3 has the ID !"qux" and the value: >> >> metadata !{ metadata !"foo", i32 1 } >> >> The behavior is to emit an error if the llvm.module.flags does not contain a >> flag with the ID !"foo" that has the value '1'. If two or more !"qux" flags >> exist, then they must have the same value or an error will be issued. >> >> >> Objective-C Metadata >> -------------------- >> >> To correctly link two or more Objective-C modules, the linker needs to know >> quite a bit of information about the language and how the modules were >> compiled. These flags are concerned with ABI versions and garbage collection, >> since they cannot conflict. The MachO writer uses these values to generate the >> "image info" section, and merges the values from different modules in an >> "intelligent" fashion rather than append them together. >> >> The supported names are: >> >> * Objective-C Version >> - The version of the Objective-C ABI. Valid values are '1' and '2'. It's an >> error for two or more Objective-C Version flags to have different values. >> >> * Objective-C Garbage Collection Version >> - The garbage collection version, used by the image info section. Currently >> always '0'. It is an error for two or more "Objective-C Garbage Collection >> Value" flags to have different values. >> >> * Objective-C Garbage Collection >> - Specifies that this module supports garbage collection. Valid values are >> '0' and '2'. A flag with the value of '0' will override one with the value >> of '2'. >> >> * Objective-C GC Only >> - Specifies that this module requires garbage collection. This requires that >> the "Objective-C Garbage Collection" metadata is present and has a value of >> '2'. If present the valid value is '4'. >> >> * Objective-C Image Info Section >> - The image info section holds information about Objective-C garbage >> collection. The "Objective-C Image Info Section" specifies the name of the >> section where the image info is placed. This flag is required if the >> "Objective-C Garbage Collection" flag is present and has the value of >> '2'. It is an error for two or more of these flags to have different >> values. >> >> Here is an example of how to use the Objective-C metadata: >> >> Module A >> -------- >> !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } >> !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } >> !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } >> !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", >> metadata !{ >> metadata !"Objective-C Image Info Section", >> metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" >> } >> } >> !4 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", >> metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } >> !llvm.module.flags = !{ !0, !1, !2, !3, !4 } >> >> Module B >> -------- >> !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } >> !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } >> !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } >> !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", >> metadata !{ >> metadata !"Objective-C Image Info Section", >> metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" >> } >> } >> !4 = metadata !{ i32 1, metadata !"Objective-C GC Only", i32 4 } >> !5 = metadata !{ i32 3, metadata !"Objective-C GC Only", >> metadata !{ >> metadata !"Objective-C Garbage Collection", i32 2 >> } >> } >> !6 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", >> metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } >> !llvm.module.flags = !{ !0, !1, !2, !3, !4, !5, !6 } >> >> Linked Module >> ------------- >> !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } >> !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } >> !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } >> !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", >> metadata !{ >> metadata !"Objective-C Image Info Section", >> metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" >> } >> } >> !4 = metadata !{ i32 1, metadata !"Objective-C GC Only", i32 4 } >> !5 = metadata !{ i32 3, metadata !"Objective-C GC Only", >> metadata !{ >> metadata !"Objective-C Garbage Collection", i32 2 >> } >> } >> !6 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", >> metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } >> !llvm.module.flags = !{ !0, !1, !2, !3, !4, !5, !6 } >> >> _______________________________________________ >> cfe-dev mailing list >> cfe-dev at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Hi Bill,> This is a proposal for implementing "module flags". Please take a look at this and give any feedback you may have.what does this give you that you can't get with the existing scheme of using global variables in a special section? Ciao, Duncan.> > Thanks! > -bw > > Module Flags Metadata > > Information about the module as a whole is difficult to convey to LLVM's > subsystems. The LLVM IR isn't sufficient to transmit this information. One > should instead use the llvm.module.flags named metadata. These flags are in the > form of a key / value pair -- much like a dictionary -- making it easy for any > subsystem who cares about a flag to look it up. > > The llvm.module.flags metadata contains a list of metadata triplets. Each > triplet has the following form: > > - The first element is a "behavior" flag, which specifies the behavior when > two (or more) modules are merged together, and it encounters two (or more) > metadata with the same ID. The supported behaviors are described below. > > - The second element is a metadata string that is a unique ID for the > metadata. How each ID is interpreted is documented below. > > - The third element is the value of the metadata. > > When two (or more) modules are merged together, the resulting llvm.module.flags > metadata is the union of the modules' llvm.module.flags metadata. The only > exception being a flag with the 'Override' behavior, which may override another > flag's value (see below). > > The following behavior flags are supported: > > Value Behavior > ----- -------- > 1 Error > Emits an error if two values disagree. > > 2 Warning > Emits a warning if two values disagree. > > 3 Require > > Emits an error when the specified value is not present or > doesn't have the specified value. It is an error for two (or > more) llvm.module.flags with the same ID to have the Require > behavior but different values. There may be multiple Require > flags per ID. > > 4 Override > Uses the specified value if the two values disagree. It is an > error for two (or more) llvm.module.flags with the same ID to > have the Override behavior but different values. > > An example of module flags: > > !0 = metadata !{ i32 1, metadata !"foo", i32 1 } > !1 = metadata !{ i32 4, metadata !"bar", i32 37 } > !2 = metadata !{ i32 2, metadata !"qux", i32 42 } > !3 = metadata !{ i32 3, metadata !"qux", > metadata !{ > metadata !"foo", i32 1 > } > } > !llvm.module.flags = !{ !0, !1, !2, !3 } > > - Metadata !0 has the ID !"foo" and the value '1'. The behavior if two or more > !"foo" flags are seen is to emit an error if their values are not equal. > > - Metadata !1 has the ID !"bar" and the value '37'. The behavior if two or more > !"bar" flags are seen is to use the value '37' if their values are not equal. > > - Metadata !2 has the ID !"qux" and the value '42'. The behavior if two or more > !"qux" flags are seen is to emit a warning if their values are not equal. > > - Metadata !3 has the ID !"qux" and the value: > > metadata !{ metadata !"foo", i32 1 } > > The behavior is to emit an error if the llvm.module.flags does not contain a > flag with the ID !"foo" that has the value '1'. If two or more !"qux" flags > exist, then they must have the same value or an error will be issued. > > > Objective-C Metadata > -------------------- > > To correctly link two or more Objective-C modules, the linker needs to know > quite a bit of information about the language and how the modules were > compiled. These flags are concerned with ABI versions and garbage collection, > since they cannot conflict. The MachO writer uses these values to generate the > "image info" section, and merges the values from different modules in an > "intelligent" fashion rather than append them together. > > The supported names are: > > * Objective-C Version > - The version of the Objective-C ABI. Valid values are '1' and '2'. It's an > error for two or more Objective-C Version flags to have different values. > > * Objective-C Garbage Collection Version > - The garbage collection version, used by the image info section. Currently > always '0'. It is an error for two or more "Objective-C Garbage Collection > Value" flags to have different values. > > * Objective-C Garbage Collection > - Specifies that this module supports garbage collection. Valid values are > '0' and '2'. A flag with the value of '0' will override one with the value > of '2'. > > * Objective-C GC Only > - Specifies that this module requires garbage collection. This requires that > the "Objective-C Garbage Collection" metadata is present and has a value of > '2'. If present the valid value is '4'. > > * Objective-C Image Info Section > - The image info section holds information about Objective-C garbage > collection. The "Objective-C Image Info Section" specifies the name of the > section where the image info is placed. This flag is required if the > "Objective-C Garbage Collection" flag is present and has the value of > '2'. It is an error for two or more of these flags to have different > values. > > Here is an example of how to use the Objective-C metadata: > > Module A > -------- > !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } > !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } > !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } > !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", > metadata !{ > metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" > } > } > !4 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } > !llvm.module.flags = !{ !0, !1, !2, !3, !4 } > > Module B > -------- > !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } > !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } > !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } > !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", > metadata !{ > metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" > } > } > !4 = metadata !{ i32 1, metadata !"Objective-C GC Only", i32 4 } > !5 = metadata !{ i32 3, metadata !"Objective-C GC Only", > metadata !{ > metadata !"Objective-C Garbage Collection", i32 2 > } > } > !6 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } > !llvm.module.flags = !{ !0, !1, !2, !3, !4, !5, !6 } > > Linked Module > ------------- > !0 = metadata !{ i32 1, metadata !"Objective-C Version", i32 2 } > !1 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection Version", i32 0 } > !2 = metadata !{ i32 1, metadata !"Objective-C Garbage Collection", i32 2 } > !3 = metadata !{ i32 3, metadata !"Objective-C Garbage Collection", > metadata !{ > metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" > } > } > !4 = metadata !{ i32 1, metadata !"Objective-C GC Only", i32 4 } > !5 = metadata !{ i32 3, metadata !"Objective-C GC Only", > metadata !{ > metadata !"Objective-C Garbage Collection", i32 2 > } > } > !6 = metadata !{ i32 1, metadata !"Objective-C Image Info Section", > metadata !"__DATA, __objc_imageinfo, regular, no_dead_strip" } > !llvm.module.flags = !{ !0, !1, !2, !3, !4, !5, !6 } > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On Wed, Jan 18, 2012 at 1:36 PM, Bill Wendling <wendling at apple.com> wrote:> Hello, > > This is a proposal for implementing "module flags". Please take a look at > this and give any feedback you may have. > > Thanks! > -bw > > Module Flags Metadata >I have only one real comment -- this violates the contract and spirit of LLVM's metadata design. You're specifically encoding semantics in metadata, but the principle of metadata is that a program with all metadata stripped has the same behavior as one with the metadata still in place. I think what you're really talking about are Module-level attributes much like we have function attributes. These have inherently significant semantics, and must be handled explicitly, not simply dropped when unknown. Anyways, that's my only real comment about the proposal. I think you need something other than metadata to encode this. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120124/4981dbb0/attachment.html>
On Jan 24, 2012, at 1:25 AM, Duncan Sands wrote:> Hi Bill, > >> This is a proposal for implementing "module flags". Please take a look at this and give any feedback you may have. > > what does this give you that you can't get with the existing scheme of using > global variables in a special section? >In the case of "image info" flags, we would need to have special code in the linker which knew to look for that special GV name, and then be able to interpret and merge two or more GVs together. It's specialized specifically to ObjC+MachO and very hacky. Placing specialized code into a generic module isn't a good idea. Also, that method isn't extensible to other potential uses (I'm suggesting they use it for some OpenCL work). And finally, because this would be defined in the LangRef document, the flags and how they're interpreted / merged would be formalized. The one LLVM submodule which cares about these flags would interpret them according to the LangRef. -bw
On Jan 24, 2012, at 1:35 AM, Chandler Carruth wrote:> On Wed, Jan 18, 2012 at 1:36 PM, Bill Wendling <wendling at apple.com> wrote: > Hello, > > This is a proposal for implementing "module flags". Please take a look at this and give any feedback you may have. > > Thanks! > -bw >> I have only one real comment -- this violates the contract and spirit of LLVM's metadata design. You're specifically encoding semantics in metadata, but the principle of metadata is that a program with all metadata stripped has the same behavior as one with the metadata still in place. > > I think what you're really talking about are Module-level attributes much like we have function attributes. These have inherently significant semantics, and must be handled explicitly, not simply dropped when unknown. > > Anyways, that's my only real comment about the proposal. I think you need something other than metadata to encode this.I had thought of that too (and having a module-level attribute scheme), but I was surprised when I found out that named metadata wasn't "strippable" from modules. (You can't strip them via the 'opt' command.) Chris assured me that they were meant to stick around... -bw